Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gitk to view the full history of a moved file

Tags:

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.

  1. 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.
  2. 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.
  3. 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.

like image 728
Kiren Padayachee Avatar asked Jan 07 '13 10:01

Kiren Padayachee


People also ask

Which command is used to view the history of all the changes to a file?

Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo .

How do you check the history of a file in git?

Git file History provides information about the commit history associated with a file. To use it: Go to your project's Repository > Files. In the upper right corner, select History.

Which command is used to view the history of the changes in git?

The git log command displays all of the commits in a repository's history. By default, the command displays each commit's: Secure Hash Algorithm (SHA) author.

How do I see old commits?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.


1 Answers

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 of git log:

git log -p --follow [file/with/path] 
like image 169
William Seiti Mizuta Avatar answered Oct 07 '22 18:10

William Seiti Mizuta