Show history of a file?

GitGithubVersion ControlGit History

Git Problem Overview


> 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.

  1. Right click on a file and select history.
  2. Scrolling through the dates and see a nice diff of exactly what changed in that file on that date. Simple.

Switching to git this is now a grueling task.

  1. "git log filename"
  2. Look at history and pick a date, copy hash
  3. "git diff hash"
  4. Scroll through diff for the stuff that changed in the file I am interested in.
  5. Nope, that's not it, lets try a different date - back to step 2, rinse and repeat.

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.

Git Solutions


Solution 1 - Git

You can use git log to display the diffs while searching:

git log -p -- path/to/file

Solution 2 - Git

Have you tried this:

gitk path/to/file

Solution 3 - Git

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 enter image description here:

Solution 4 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChrisView Question on Stackoverflow
Solution 1 - GitralphtheninjaView Answer on Stackoverflow
Solution 2 - GitPierre MageView Answer on Stackoverflow
Solution 3 - GitJeff FerlandView Answer on Stackoverflow
Solution 4 - GitLiKaoView Answer on Stackoverflow