开发者

How do i view the index version of a file before it is committed?

I have just performed git add --interactive, so the index version of some files is different than the working-directory versions. Instead of doing git diff --cached, I want to actually dump the contents of each file in the index, but I can't find a command to do that. I should t开发者_运维百科hink that there would be something like git show INDEX:filename..., but "INDEX" is not a valid object name.

I was able to do git ls --cached, then git show <hash>, but there should be a more straightforward method to see what you are committing.


Yes, simply:

git show :filename

If you have multiple index versions (such as in a merge conflict situation) you can view versions in different index slots with:

git show :1:filename
git show :2:filename
git show :3:filename

In most other situations only slot 0 is populated and :0:filename is the identifer for the cached version of the file. :filename is a shorthand for :0:filename.


If you want to test the version of project that you have stashed in the index, you can use git stash --keep-index (see "Testing partial commits" section in git-stash manpage).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜