I have a number of GitHub projects on my disk, but many of them are not in active use.
I would like to remove the working files for the time being, because they are stored in the commit history anyway, so I can retrieve them at a later time.
The easiest way to remove the files is rm -rf *
but it has a number of drawbacks:
.gitignore
git status
complains about lots of removed files. I have to work out whether I should commit these removals, or if I had just removed them to temporarily save space. What is a quick and easy way to remove the working files? And is there a way to do it cleanly?
Creating an empty branch seems to work quite nicely:
Create an empty branch. I will call it "empty".
git checkout --orphan empty
But that didn't remove the files. Do that manually:
git reset --hard
The branch doesn't really exist yet. Make an initial commit to confirm it:
git commit --allow-empty -m 'Empty commit'
Now all your files are gone, and you are on a branch that embodies that situation.
Good things about this process:
git checkout master
git checkout empty
Disadvantages:
If you use git 2.5.1 or higher, you can use bare repositories, and use git worktree add /some/checkout/path branch
if you want to inspect or use its content.
The worktree will work exactly as a standard git clone, expect that all modifications you run there (commits, new branches, tags, ...) are applied to the bare clone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.