Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Viewing GIT history of moved files

Tags:

git

Despite reading lots of other posts regarding GIT and moved files I still struggle to understand how to trace the full history. Doing gitk myfile as suggested here seems to only show history until the previous move. I understand that GIT doesn't track files, only their content. So surely I should be able to view the full evolution of a file, even if it's been moved?

Can anyone direct me to a good yet simple example/tutorial?

I'd like to see an example where some files are moved around, changed and committed, then the history of a single file is displayed, moves and all. I've been looking at 'log' but that seems to concern checkins. Would still appreciate some advice, even if its says I'm somehow still thinking too much SVN.

like image 961
Pengin Avatar asked Oct 02 '10 10:10

Pengin


People also ask

How do I see file history 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.

Does git keep track of moved files?

Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).

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

Use --follow option in git log to view a file's history This lists out the commits of both the files.


2 Answers

Try using the --follow option to git log:

git log --follow file.txt 
like image 122
Greg Hewgill Avatar answered Oct 21 '22 14:10

Greg Hewgill


Use git log with both --follow and --patch which will display the log with the rename from / rename to output. And don't forget the -- before the file path.

git log --follow --patch -- path/to/file.ext 

For example the history of file testdir/more-testing.txt on my system shows:

Date:   Wed Mar 18 14:48:07 2020 -0700     renamed file  diff --git a/testdir/testing.txt b/testdir/more-testing.txt similarity index 100% rename from testdir/testing.txt rename to testdir/more-testing.txt  commit feb58d3ab8e8ce940f80499df0c46e8fc8caf679 Author: Igal <redacted> Date:   Wed Mar 18 14:47:18 2020 -0700     moved test.txt to subdirectory and renamed  diff --git a/test.txt b/testdir/testing.txt similarity index 100% rename from test.txt rename to testdir/testing.txt  commit 34c4a7cebaeb0df5afb950972d69adea6b1a7560 Author: Igal <redacted> Date:   Wed Mar 18 14:45:58 2020 -0700     added test.txt  diff --git a/test.txt b/test.txt new file mode 100644 index 000000000..0527e6bd2 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +This is a test (END)  
like image 30
isapir Avatar answered Oct 21 '22 14:10

isapir