After reading an answer to a question on here on moving files tracked by git, the history should not be impacted if you move a file that git is tracking. However that is not my experience, so what am I doing wrong? Here is my console log
C:\scripts\Python\Cyren>mkdir archive
C:\scripts\Python\Cyren>dir
Volume in drive C has no label.
Volume Serial Number is 7C59-18A2
Directory of C:\scripts\Python\Cyren
08-May-22 22:44 <DIR> .
08-May-22 22:44 <DIR> ..
08-May-22 22:43 <DIR> archive
31-Mar-22 19:11 1,878 categories.csv
31-Mar-22 17:57 1,886 categories.txt
30-Mar-22 21:19 14,557 categories.xlsx
29-Apr-22 16:23 19,274 CyrenDopplerAPI.py
06-May-22 12:35 14,585 CyrenDopplerEnv.py
29-Apr-22 16:16 17,672 CyrenSample.py
C:\scripts\Python\Cyren>git log CyrenDopplerAPI.py
commit 4f440a2c132053ebe9c76a16e90abc1dd845d262
Author: Siggi@Reba <[email protected]>
Date: Thu May 5 15:38:58 2022 0000
rename
C:\scripts\Python\Cyren>git mv CyrenDopplerAPI.py archive
C:\scripts\Python\Cyren>dir
Volume in drive C has no label.
Volume Serial Number is 7C59-18A2
Directory of C:\scripts\Python\Cyren
08-May-22 22:48 <DIR> .
08-May-22 22:48 <DIR> ..
08-May-22 22:48 <DIR> archive
31-Mar-22 19:11 1,878 categories.csv
31-Mar-22 17:57 1,886 categories.txt
30-Mar-22 21:19 14,557 categories.xlsx
06-May-22 12:35 14,585 CyrenDopplerEnv.py
05-May-22 18:24 109 Infile.txt
06-May-22 12:35 <DIR> Logs
5 File(s) 33,015 bytes
4 Dir(s) 484,630,781,952 bytes free
C:\scripts\Python\Cyren>git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
renamed: CyrenDopplerAPI.py -> archive/CyrenDopplerAPI.py
renamed: CyrenSample.py -> archive/CyrenSample.py
C:\scripts\Python\Cyren>git commit -m "cleanup and archiving"
[master 1240039] cleanup and archiving
2 files changed, 0 insertions( ), 0 deletions(-)
rename Cyren/{ => archive}/CyrenDopplerAPI.py (100%)
rename Cyren/{ => archive}/CyrenSample.py (100%)
C:\scripts\Python\Cyren>git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
C:\scripts\Python\Cyren>git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 454 bytes | 454.00 KiB/s, done.
Total 4 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/siggib007/python.git
e85489f..1240039 master -> master
C:\scripts\Python\Cyren>git log archive\CyrenDopplerAPI.py
commit 1240039a7e93993027f22979908ee4a9837a5474 (HEAD -> master, origin/master)
Author: Siggi@Reba <[email protected]>
Date: Sun May 8 22:49:03 2022 0000
cleanup and archiving
The git log
isn't showing anything before the move. I take that to mean that it was erased.
BTW Here is the link the corrensponding github repo https://github.com/siggib007/python/tree/master/Cyren
Also this is not an isolated incident, this is consolelog from me reproducing an issue I've noticed couple of times before.
CodePudding user response:
Use git log --follow
to track renames.
--follow
Continue listing the history of a file beyond renames (works only for a single file).
You can make this the default by setting the log.follow
configuration option to true
:
log.follow
If
true
,git log
will act as if the--follow
option was used when a single is given. This has the same limitations as--follow
, i.e. it cannot be used to follow multiple files and does not work well on non-linear history.
To set it run:
$ git config --global log.follow true