2

How can I cleanup git working file set (like hg up -r null)?

So only $proj/.git hierarchy present and git st don't show D (deleted).

gavenkoa
  • 45,285
  • 19
  • 251
  • 303
  • possible duplicate of [How to remove working tree from a Git repository](http://stackoverflow.com/questions/7380741/how-to-remove-working-tree-from-a-git-repository) – Mark Longair Nov 01 '11 at 10:21
  • ... or http://stackoverflow.com/q/2199897/223092 – Mark Longair Nov 01 '11 at 10:22
  • @Mark Longair. Similar but not exactly same. **git config core.bare true** does not delete working tree... – gavenkoa Nov 01 '11 at 10:29
  • What's mentioned in both of those answers is that you can just move your `.git` directory to somewhere else, set that config option, and it's a bare repository. You can then just delete the working tree directory that used to also contain the `.git` directory. – Mark Longair Nov 01 '11 at 10:34
  • I exactly that git can not perform such operation. It is possible update to **ZERO** rev? that is much exactly that **hg up -r null** do... – gavenkoa Nov 01 '11 at 11:02
  • What are you really trying to do? Do you want to create a new *root* commit, with no files in it? Or do you want to create a new commit on top of your current one, but where all the files in your repository are removed? – Mark Longair Nov 01 '11 at 11:10

2 Answers2

3

After clarifications in your comments, it seems that you want to create a new root commit in your repository. There's a description of how to do this in the git community book.

First, make sure that the output of git status is clean, so that you don't lose any of your previous work unintentionally. Then if you do the following:

git symbolic-ref HEAD refs/heads/newbranch 
rm .git/index 
git clean -fdx 
git commit --allow-empty -m 'Initial empty commit'

Then you will be on a new branch called newbranch, with a single root commit with an empty tree. If you then decide that you want this to be your new master branch, you can do:

git branch -m master oldmaster
git branch -m newbranch master

... which renames your old master branch to oldmaster, and then renames the new newbranch branch to master.

Mark Longair
  • 446,582
  • 72
  • 411
  • 327
2

Alternative to what @Mark Longair mentioned, using git checkout --orphan:

git checkout --orphan newbranch
git rm -rf .
git commit --allow-empty -m 'Initial empty commit'

Much more straightforward in my opinion

manojlds
  • 290,304
  • 63
  • 469
  • 417