开发者

Can I view at which changeset a particular file is , using git?

$ git init
$ echo zero > a
$ git add a
$ git commit -m zero
$ echo other &g开发者_运维问答t; a
$ git add a
$ git commit -m other
$ echo whatever > a
$ git add a
$ git commit -m whatever

I'm checking out the file as it was when I commited the 2nd time, when the file contained the text other.

$ git checkout HASH_OF_COMMIT_OTHER a
$ cat a
other
$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   a
#

What command should I run on a, so that git will tell at which changeset it currently is? In this case I would like it to show me the hash of the 2nd commit, along with the commit message, if possible.


Once you've run the command git checkout HASH_OF_COMMIT_OTHER a, the working tree and the index are updated with the version of a from HASH_OF_COMMIT, but there's no record preserved of how the file was changed to be in that state. This is part of git's philosophy of tracking content - it doesn't matter how the file got into the state it is at a certain commit, it just records the exact content of the files at each one.

You could certainly write a short script to find all commits that contained a file with exactly that content (and at that path) if you like, but normally one wouldn't need to.


After a great deal of searching for ways to do it using standard git commands I was lead back to this SO question which has just what you are looking for.

Which commit has this blob?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜