How to Trace the History of a Renamed File with git log –follow
Running git log --follow -- file traces the history of a file even after it has been renamed or moved, back to the commits made under its old name. Use it when you run git mv to rename a file or move it to another folder, and the change history then appears to stop at the move commit. I ran the git commands in a test environment and show the output before and after adding --follow as it was printed.
The test environment is Ubuntu 24.04 with Git 2.43.0. I set the author name and email to example values (Neko <neko@example.com>). The output was saved to a file, so there are no colors and no pager was used. I did not test Windows or macOS, copy detection with -C, or viewing history in GUI tools.
- 1. The history of a renamed file stops partway
- 2. Adding –follow traces back to before the rename
- 3. If you change the name and the content heavily in the same commit, –follow cannot trace it
- 4. Pass only one file
- 5. To always use it, set log.follow
- 6. With branched history, some commits are missed
- 7. Running git log does not change the repository
The history of a renamed file stops partway
I prepared a repository called neko-memo. I created a feeding memo for the cat, memo.md, added to it, moved it to docs/food.md with git mv, and then edited it again.
$ git log --oneline
fe87998 夜のカリカリを35gにする
efcb9c9 メモを docs/food.md に移す
a1571c0 README を追加
eb77a67 昼のおやつを足す
f50d7f4 ごはんメモを作る
When I looked at the history using the current name docs/food.md, nothing before the move commit appeared. The two commits that created the memo and added the lunch treat were still under the name memo.md.
$ git log --oneline -- docs/food.md
fe87998 夜のカリカリを35gにする
efcb9c9 メモを docs/food.md に移す
Adding –follow traces back to before the rename
I added --follow to the same command.
$ git log --oneline --follow -- docs/food.md
fe87998 夜のカリカリを35gにする
efcb9c9 メモを docs/food.md に移す
eb77a67 昼のおやつを足す
f50d7f4 ごはんメモを作る
The two commits made when the file was memo.md now appear. The README commit does not appear because it did not change this file. The git log reference describes --follow as an option that "continues listing the history of a file even across renames," and says it only works with a single file.
The diffs show the names used at the time
Adding -p also shows the diff for each commit.
$ git log --follow -p -- docs/food.md
commit fe879987833ff4d91a0eecf434ee1ca4bbdfe3f5
Author: Neko <neko@example.com>
Date: Thu Nov 12 12:00:00 2026 +0900
夜のカリカリを35gにする
diff --git a/docs/food.md b/docs/food.md
index 7e98a01..be00509 100644
--- a/docs/food.md
+++ b/docs/food.md
@@ -2,4 +2,4 @@
- 朝:カリカリ 30g
- 昼:おやつ 1本
-- Night: crispy kibble 30g
+- 夜:カリカリ 35g
commit efcb9c9d322d4eef47add2ff87ae279f26f2c7fa
Author: Neko <neko@example.com>
Date: Thu Nov 12 11:30:00 2026 +0900
メモを docs/food.md に移す
diff --git a/memo.md b/docs/food.md
similarity index 100%
rename from memo.md
rename to docs/food.md
commit eb77a6762aaacfdb319094bcb57863a4de10c110
Author: Neko <neko@example.com>
Date: Thu Nov 12 10:30:00 2026 +0900
昼のおやつを足す
diff --git a/memo.md b/memo.md
index 6fedec4..7e98a01 100644
--- a/memo.md
+++ b/memo.md
@@ -1,4 +1,5 @@
# Cat food note
- 朝:カリカリ 30g
+- 昼:おやつ 1本
- 夜:カリカリ 30g
commit f50d7f4e068df9d7eb189d254180d1b3634ab350
Author: Neko <neko@example.com>
Date: Thu Nov 12 10:00:00 2026 +0900
ごはんメモを作る
diff --git a/memo.md b/memo.md
new file mode 100644
index 0000000..6fedec4
--- /dev/null
+++ b/memo.md
@@ -0,0 +1,4 @@
+# Cat food note
+
+- 朝:カリカリ 30g
+- 夜:カリカリ 30g
For commits before the move, the diff uses the old name, as in a/memo.md b/memo.md. The move commit has no content diff. rename from memo.md and rename to docs/food.md show which name changed to which. According to the git log reference's explanation of the diff format, the similarity index is the percentage of unchanged lines, and 100% is used only when the two files are identical.
If you add --stat instead of -p, the move commit appears on one line as memo.md => docs/food.md. This is easier to scan when you want to quickly find which commit changed the name.
$ git log --oneline --follow --stat -- docs/food.md
fe87998 夜のカリカリを35gにする
docs/food.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
efcb9c9 メモを docs/food.md に移す
memo.md => docs/food.md | 0
1 file changed, 0 insertions(+), 0 deletions(-)
eb77a67 昼のおやつを足す
memo.md | 1 +
1 file changed, 1 insertion(+)
f50d7f4 ごはんメモを作る
memo.md | 4 ++++
1 file changed, 4 insertions(+)
To see the contents of an older commit, use its old name
When you retrieve a file from an older commit found with --follow using git show commit:path, write the name it had at that time. Using the current name returned an error because the file does not exist in that commit.
$ git show eb77a67:memo.md
# Cat food note
- 朝:カリカリ 30g
- 昼:おやつ 1本
- 夜:カリカリ 30g
$ git show eb77a67:docs/food.md
fatal: path 'docs/food.md' exists on disk, but not in 'eb77a67'
Also, running git log -- memo.md with the old name lists the three commits up to the move. If you know the old name, you can also view the history from before the move this way.
$ git log --oneline -- memo.md
efcb9c9 メモを docs/food.md に移す
eb77a67 昼のおやつを足す
f50d7f4 ごはんメモを作る
If you change the name and the content heavily in the same commit, –follow cannot trace it
Next, in the same commit that renamed docs/food.md to docs/gohan.md, I changed the heading, added lines, and rewrote the night line. When I look at this commit with --name-status, it appears as a deletion (D) and an addition (A), not as a rename (R).
$ git show --name-status --oneline HEAD
ca4f381 書き足して gohan.md にする
D docs/food.md
A docs/gohan.md
With --follow in this state, the history still stopped at the commit where the name changed.
$ git log --oneline --follow -- docs/gohan.md
ca4f381 書き足して gohan.md にする
According to the -M explanation in the official reference, Git decides whether something is a rename based on how similar the contents of a deleted file and an added file are (the similarity index). The default threshold is 50%. You can change this threshold by specifying a number such as -M30%.
Adding -M30% showed this commit as a rename (R031). According to the explanation of the output format in the git diff reference, the number after R is the percentage of similarity between the old and new files. In this case it was 31%.
$ git show --name-status --oneline -M30% HEAD
ca4f381 書き足して gohan.md にする
R031 docs/food.md docs/gohan.md
When I added -M30% together with --follow, the history traced back to the commit that created memo.md.
$ git log --oneline --follow --name-status -M30% -- docs/gohan.md
ca4f381 書き足して gohan.md にする
R031 docs/food.md docs/gohan.md
fe87998 夜のカリカリを35gにする
M docs/food.md
efcb9c9 メモを docs/food.md に移す
R100 memo.md docs/food.md
eb77a67 昼のおやつを足す
M memo.md
f50d7f4 ごはんメモを作る
A memo.md
If you put a rename and a large rewrite in the same commit, --follow may fail to detect the rename. Keeping commits that only run git mv separate from commits that rewrite content makes the history easier to trace later.
Pass only one file
When I passed two files to --follow, it stopped with an error.
$ git log --oneline --follow -- docs/gohan.md README.md
fatal: --follow requires exactly one pathspec
Passing a folder did not produce an error, but it did not trace back before the commit that created files in docs. The commits made when the file was memo.md did not appear.
$ git log --oneline --follow -- docs
ca4f381 書き足して gohan.md にする
fe87998 夜のカリカリを35gにする
efcb9c9 メモを docs/food.md に移す
To always use it, set log.follow
Setting git config log.follow true makes the command behave as if --follow were added whenever you pass exactly one file. To turn it off for a single run, add --no-follow.
$ git config log.follow true
$ git log --oneline -M30% -- docs/gohan.md
ca4f381 書き足して gohan.md にする
fe87998 夜のカリカリを35gにする
efcb9c9 メモを docs/food.md に移す
eb77a67 昼のおやつを足す
f50d7f4 ごはんメモを作る
$ git log --oneline --no-follow -M30% -- docs/gohan.md
ca4f381 書き足して gohan.md にする
When I passed two files, there was no error. It worked as a regular git log without --follow.
$ git log --oneline -- docs/gohan.md README.md
ca4f381 書き足して gohan.md にする
a1571c0 README を追加
The log.follow explanation in the git config reference also says it behaves like --follow when you pass one file. As with --follow, multiple files cannot be traced, and it does not work well with branched history. After testing, I removed the setting with git config --unset log.follow.
With branched history, some commits are missed
The log.follow explanation says it does not work well with branched history. So in another repository, neko-branch, I tested a case where a rename happened on one side of a branch and was then merged. On the rename branch I changed list.txt to items.txt. Meanwhile, on main I added a line "9" to list.txt. Finally I merged rename into main.
$ git log --oneline --graph
* 2e7e01f Merge branch 'rename'
|\
| * 1b532fe items.txt に名前を変える
* | 70a71c5 main で 9 を足す
|/
* e009e9e リストを作る
After the merge, items.txt contains the line "9" that was added on main.
$ cat items.txt
1
2
3
4
5
6
7
8
9
However, when I looked at the history of items.txt with --follow, the commit 70a71c5 that added "9" did not appear. It only followed the branch where the name was changed.
$ git log --oneline --follow -- items.txt
1b532fe items.txt に名前を変える
e009e9e リストを作る
When I passed both the old and new names without --follow, all four commits appeared. If you know the old name, this form shows commits from both before and after the rename.
$ git log --oneline -- items.txt list.txt
2e7e01f Merge branch 'rename'
70a71c5 main で 9 を足す
1b532fe items.txt に名前を変える
e009e9e リストを作る
Running git log does not change the repository
Finally, I checked the state of neko-memo. git log only displays history, so the working tree has no changes and no commits were added.
$ git status --short
$ git log --oneline
ca4f381 書き足して gohan.md にする
fe87998 夜のカリカリを35gにする
efcb9c9 メモを docs/food.md に移す
a1571c0 README を追加
eb77a67 昼のおやつを足す
f50d7f4 ごはんメモを作る




