Possible Duplicate:
View the change history of a file using Git versioning
Sometimes I want to step through the history of a particular file. In the past I used P4V and this was very quick and intuitive.
Switching to git this is now a grueling task.
I've searched SO, and I've tried a few of the commonly suggested guis: github, gitk, gitg, git-gui.
These all remove the need to manually run commands, but the workflow is the same for this. View history of file; view commit; search through diff of lots of irrelevant files. It's slow and repetitive.
All the data is in the repo so I see no reason this simple common use case could not be more streamlined.
Can anyone recommend a tool that does this - or a more efficient way to utilize the command line to do what I want?
Thanks for any suggestions.
This question is related to
git
github
version-control
git-history
git log -p
will generate the a patch (the diff) for every commit selected. For a single file, use git log --follow -p $file
.
If you're looking for a particular change, use git bisect
to find the change in log(n) views by splitting the number of commits in half until you find where what you're looking for changed.
Also consider looking back in history using git blame
to follow changes to the line in question if you know what that is. This command shows the most recent revision to affect a certain line. You may have to go back a few versions to find the first change where something was introduced if somebody has tweaked it over time, but that could give you a good start.
Finally, gitk
as a GUI does show me the patch immediately for any commit I click on.
Example :
You can use git log to display the diffs while searching:
git log -p -- path/to/file
The main question for me would be, what are you actually trying to find out? Are you trying to find out, when a certain set of changes was introduced in that file?
You can use git blame
for this, it will anotate each line with a SHA1 and a date when it was changed. git blame
can also tell you when a certain line was deleted or where it was moved if you are interested in that.
If you are trying to find out, when a certain bug was introduced, git bisect
is a very powerfull tool. git bisect
will do a binary search on your history. You can use git bisect start
to start bisecting, then git bisect bad
to mark a commit where the bug is present and git bisect good
to mark a commit which does not have the bug. git will checkout a commit between the two and ask you if it is good or bad. You can usually find the faulty commit within a few steps.
Since I have used git, I hardly ever found the need to manually look through patch histories to find something, since most often git offers me a way to actually look for the information I need.
If you try to think less of how to do a certain workflow, but more in what information you need, you will probably many workflows which (in my opinion) are much more simple and faster.
Source: Stackoverflow.com