1

I want to implement feature to save changes in working directory before git reset --hard HEAD^ as detached head.

According to this question there are many people who lost their work.

So I offer next scenario for git reset --hard <sha>:

1. `git add .`
2. `git commit -m 'Reset hard'`
3. `git reset --hard <sha>`

So if I need to restore lost working directory I will use git fsck --lost-found

Will it be useful to have next feature in git?

If it will what is the source file which is responsible for git reset command?

Community
  • 1
  • 1
Eugen Konkov
  • 22,193
  • 17
  • 108
  • 158
  • This question would be more appropriate on [the git mailing list](http://vger.kernel.org/vger-lists.html#git), not on SO. – Ismail Badawi Dec 24 '16 at 19:32
  • why not just `git stash`? – Andy Ray Dec 25 '16 at 01:07
  • @AndyRay Because you may forget `git stash` before `git reset --hard`. With this you have one more chance to restore your work – Eugen Konkov Dec 25 '16 at 01:09
  • @EugenKonkov, `git reset --hard` was designed to reset without backup. If you need a backup then you definitely using wrong command. Could you please explain what is the purpose of "reset" in your case? And what do you plan to do with "backup"? We need those answers in order to be able to help you. – Victor Yarema Dec 25 '16 at 05:15
  • @VictorYarema I gorget to start branch and make commit into master that I do not push yet. Then: 1. `git checkout -b branch_name` 2. `git checkout master` And I want to drop last commit from master: 3. `git reset --hard HEAD^` I forgot I have some changes in working directory I should stash them or use `--soft` switch maybe. That is my fault. I know. But with scenario I have describe in question I have a chance to restore working directory until git compression – Eugen Konkov Dec 25 '16 at 15:00

1 Answers1

2

First, should you implement that feature, you would not need to use git fsck --lost-found: sonce you just made a commit, you would see (and restore if needed) that commit in git reflog.

Second, builtin/reset.c is the file implementing git reset.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250