how to restart a git repository

匆匆过客 提交于 2019-12-05 17:16:46

问题


I am a newbie with git – and just realized changes to the .gitignore does not process against the repo “retroactively” – rather affect future ‘git add *’ commands and the like. Once the files are in the repo – they must be manually removed.

At this point – I would like just kill this repo entirely – and start over (saving my config, etc.).

Is this easily possible or would it cause major problems? Can backup – then delete the .git folder – and start fresh?

Also – for others newbies just starting in git I would suggest viewing this video. It describes not how to use git – but how git works internally – and I found it eye opening. It’s titled git for ages 4 and up. http://blip.tv/open-source-developers-conference/git-for-ages-4-and-up-4460524

Resolution:

I want to thank everyone for their input and guidance.

I did try to delete the .git directory - and restart. I am not sure how - but when I did try to start it over - It started up with full awareness of it's history - and in short recreated itself to include all the previous commits and tracking.

I left that alone - and set about reorganizing and restructuring and cleaning. Changing the folder structure - deleted unnecessary projects, folders, etc.. - and in the process - realized what I could do to remove the files I did not want tracked (but still wanted them present in the tree).

I effectively moved every folder, etc. and when I would commit this - git removed the tracking on the moved / deleted files. But because of the .gitignore I now had - it did not pick up or track the files in the moved folders.

Much of what I was doing was in preparation to start a whole new git repo. Late in the process I't dawned on me - most of what I did not want tracked had been effectively been removed for the repo. So took what had happened - and made a few more adjustments - and all is fine now.

Once again - thank you. I'm loving git!


回答1:


Can backup – then delete the .git folder – and start fresh?

Yes. This is all there is to it.

Some really exotic set-ups might have the .git folder outside of the working directory; but otherwise the .git folder contains all the information there is wrt git. If you remove that, you remove all history, git-metadata and such.

If you had remotes, the link to them is lost, as that is stored in the same .git folder. The remote itself, on say your Gitlab server, is obviously not gone. So if you re-add that same remote on your clean environment it will cause history to re-appear, which might cause merge conflicts.

Edit: for those who might not have read the entire question: warning: this will remove all your git history.




回答2:


I do this all the time. got into the working directory and if your on linux or mac do a

rm -rf .git

then I do a

git init
git add .
git commit -m "first time load"

that's all you need




回答3:


The best strategy for handling this would be to use the git archive command. This will export an unversioned version of your tree in a tar archive. Select your branch that you'd like to export and run the following inside your repository:

git archive master | tar -x -C ~/target/directory

You can then cleanly delete your repository folder and then extract your archive to start anew. Finally, you can create a new repository in your extracted folder as follows:

git init


来源:https://stackoverflow.com/questions/15244644/how-to-restart-a-git-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!