View the change history of a file using Git versio

2018-12-31 22:48发布

How can I view the change history of an individual file in Git, complete details with what has changed?

I have got as far as:

git log -- [filename]

which shows me the commit history of the file, but how do I get at the content of each of the file changes?

I'm trying to make the transition from MS SourceSafe and that used to be a simple right-clickshow history.

标签: git git-log
21条回答
明月照影归
2楼-- · 2018-12-31 23:18

Summary of other answers after reading through them and playing a bit:

The usual command line command would be

git log --follow --all -p dir/file.c

But you can also use either gitk (gui) or tig (text-ui) to give much more human-readable ways of looking at it.

gitk --follow --all -p dir/file.c

tig --follow --all -p dir/file.c

Under debian/ubuntu, the install command for these lovely tools is as expected :

sudo apt-get install gitk tig

And I'm currently using:

alias gdf='gitk --follow --all -p'

so that I can just type gdf dir to get a focussed history of everything in subdirectory dir.

查看更多
柔情千种
3楼-- · 2018-12-31 23:19

Lately I discovered tig and found it very useful. There are some cases I'd wish it does A or B but most of the time it's rather neat.

For your case, tig <filename> might be what you're looking for.

http://jonas.nitro.dk/tig/

查看更多
伤终究还是伤i
4楼-- · 2018-12-31 23:20

With the excellent Git Extensions, you go to a point in the history where the file still existed (if it have been deleted, otherwise just go to HEAD), switch to the File tree tab, right-click on the file and choose File history.

By default, it follows the file through the renames, and the Blame tab allows to see the name at a given revision.

It has some minor gotchas, like showing fatal: Not a valid object name in the View tab when clicking on the deletion revision, but I can live with that. :-)

查看更多
孤独寂梦人
5楼-- · 2018-12-31 23:21

To show what revision and author last modified each line of a file:

git blame filename

or if you want to use the powerful blame GUI:

git gui blame filename
查看更多
孤独总比滥情好
6楼-- · 2018-12-31 23:22

The answer I was looking for that wasn't in this thread is to see changes in files that I'd staged for commit. i.e.

git diff --cached
查看更多
路过你的时光
7楼-- · 2018-12-31 23:23

If you are using eclipse with the git plugin, it has an excellent comparison view with history. Right click the file and select "compare with"=> "history"

查看更多
登录 后发表回答