Is there a reflex for the index?

I have no specific problem, but in the past I came across some cases when I accidentally blew up my index, and wanted me to be able to return to the previous state of this file, which was indexed at some point.

Some examples:

$ git add <file>
# find out that I already had an indexed version of <file>,
# and that for some reason I shouldn't have added the extra modifications

$ git stash pop
# find out afterwards that I have a mix of "the index I had"
# and "the index in the stash"

$ git stash
# with an active index, which is now mixed with the state of the working tree

$ git reset <typo>
# accidentally resetting the wrong file, or the whole directory

You could resort to digging through git fsck --full --unreachable --no-reflog(as suggested here ), I was wondering if there is a more convenient way to do this.

Question:

Is there any reflog for the index?

+4
source share
2 answers

The reflog contains entries for links ... not an index.

But maybe setting up the workflow is the answer here ... (it was for me).

, 5-10 , commit-as-you-go ( ). , .

index ... ! , , ( , ). , , - .

, , , , , . , , .

, , , ( ), wip , .

, .

:

# start work
git checkout -b featurea
# work
vim file.txt
# reach a little milestone
git commit -a -m "working on feature..."
# work some more
vim file.txt
# reach another little milestone
git commit -a --reuse-message=HEAD --amend
# work some more
vim file.txt
# another little milestone...
git commit -a --reuse-message=HEAD --amend
# finishing touches...
vim file.txt
# ok, done now, put everything back in working dir so I can review
git reset HEAD~
# decide what goes in this commit
# perhaps use `git add -p`
git add file.txt
# give a nice commit message (use editor)
git commit
# now merge to master and push with confidence!

, ( set -o emacs set -o vi - ), .

, , , , , "", - , , .

+4

, reflog. , git fsck --lost-found .

(SHA-1) "" , .

+1

All Articles