2

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
Sony Antony
  • 314
  • 1
  • 11

1 Answers1

2

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:

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried both --no-rename and also -M100% to no avail. – Sony Antony Jun 22 '20 at 16:20
  • @SonyAntony Why are you using the same name for `git rm` and the new file? The idea to avoid a common log is to avoid it between two different files with different names but similar content: `git rm file1`, and commit, then `git add file2` and commit. – VonC Jun 22 '20 at 16:40
  • @SonyAntony Is your worflow based on deleting, then adding again the *same* file name? – VonC Jun 22 '20 at 19:44
  • No @VonC ...As I said, I was just trying out various things in git.. This just happened to be a behavior I did not expect – Sony Antony Jun 23 '20 at 00:43
  • @SonyAntony Git determines the "file identity" through its content: https://stackoverflow.com/a/55617347/6309 (and https://stackoverflow.com/a/36563833/6309). Example: https://stackoverflow.com/a/51662141/6309. More on history and similarity: https://stackoverflow.com/a/51795091/6309 – VonC Jun 23 '20 at 05:14