After much searching, I have not found a satisfactory method that is easy to use to view the complete history of a moved file in Git and more importantly in Gitk. Using "git log --follow [filePath]" and even "gitk --follow [filePath]" gives you the commits that the file was involved in but will not show you the actual change history of the file before the move. I have thus come up with a crude but simple workaround solution.
- Do a gitk on the file that has been moved : “gitk [newFilePath]”. Copy the SHA1 ID of the first commit, this should be the commit where the file has been moved.
- Do a gitk on the copied SHA1 ID : “gitk [SHA1ID]”. The latest commit should be when the move has happened. Find the moved file and copy the old path.
- Do a gitk on the SHA1 ID we just copied and the old file path : “gitk [SHA1ID] -- [oldFilePath]”
This process will allow you to view the history of the file before the move. If there have been multiple moves the above process can be repeated.
If there are any better solutions to this problem, especially if there is a way to combine these steps to display the full history with the moves, it would be highly appreciated.
Another alternative is to use the SourceTree application (GUI) developed by Atlassian. Inside the application you can right-click on the file and select "Log Selected ..."
.
In the pop-up window it then allows you to "Follow renamed files":
I also use GitHub for Mac, but didn't see that kind of functionality in there, yet.
(I am not affiliated with either of them!)
A simpler function using different git log options and awk to exact the file names (and the "--" that gitk needs is included):
Here's a bash function that should show you the history of a file (using gitk) in all its incarnations ... I'll leave it as an exercise to the reader if they need it for another shell:
updated:
Changed to use perl because I didn't pay close enough attention to the output from git log in the last version.
If you want to see the changes that was made in each commit even the file has been renamed, you can use the option
-p
ofgit log
: