Reputation: 346
I have a file that I removed using git rm
after which I committed successfully.
Later on, I created a new file named after the original file and commit successfully.
But when I look at git log file.txt
on this file, instead of seeing a single commit, I see the history of the earlier deleted file.
I was expecting the deleted file to be distinct and unrelated to the new file although both are named the same.
I tried with --follow
and I still see the same behaviour.
Did I miss something? (Or is this a bug? I’m using version 2.25 of git on Fedora )
git --version
git init
touch master.txt ; git add . ; git commit -m "Master original created"
git rm master.txt ; git commit -m "Master original Removed"
echo junk >dummy ; git add . ; git commit -m "Dummy Commit"
echo "only line in Master" >master.txt ; git add . ; git commit -m "Master New Created"
git log --oneline --no-rename master.txt
git log --oneline -M100% --no-rename master.txt
========================================
it version 2.25.1
Reinitialized existing Git repository in /home/sony/gitwork/tt/.git/
On branch master
nothing to commit, working tree clean
rm 'master.txt'
[master ad596ad] Master original Removed
1 file changed, 1 deletion(-)
delete mode 100644 master.txt
On branch master
nothing to commit, working tree clean
[master 02492e1] Master New Created
1 file changed, 1 insertion(+)
create mode 100644 master.txt
02492e1 (HEAD -> master) Master New Created
ad596ad Master original Removed
42c32af Master New Created
1a057ca Master original Removed
beb0903 Master original created
02492e1 (HEAD -> master) Master New Created
ad596ad Master original Removed
42c32af Master New Created
1a057ca Master original Removed
beb0903 Master original created
Upvotes: 2
Views: 103
Reputation: 1323793
This is not a bug, but the result of the Git rename detection based on the content of the file, similar enough for Git to consider the new file to be the old one, renamed.
A git log --no-rename
would not display the past commits.
Buy the true solution would be to undo that commit, and:
Upvotes: 2