0

When I rename a zip file and modifies it I lose the file history. Since Git recognize it as a new file .I tried git log command with --follow and git GUI
tools like TortoiseGit or git extension options to view a file history.
I am using Git-lfs to track all *.zip files and I also tried using textconv for the diff of zip files in hope it will help.
my configuration for the textconv

   .gitattributes:  
          *.zip filter=lfs diff=zip merge=lfs -text

    .gitconfig file :  
        [diff "zip"]           
            textconv = unzip -c -a  
            binary = true

How to preserve "result.zip" history in Git after a commit that contained renaming it to "result_Two.zip" and modifying it ?

Salty Orn
  • 51
  • 1
  • 2

2 Answers2

1

Make one commit that merely renames the zip file:

git mv foo.zip bar.zip
git commit -s 'rename zip file without any other changes'

Then, make a commit that completely replaces the contents:

<create new bar.zip>
git add bar.zip
git commit -s 'replace bar.zip contents'

Afterward, running:

git log --follow bar.zip

will show, in Git's usual backwards fashion, the "replace contents" commit, then the "rename" commit, then whatever commits affect foo.zip (the old name).

torek
  • 448,244
  • 59
  • 642
  • 775
0

It is not possible to keep the history if a file is renamed.

Renames are handled implicitly rather than explicitly. A common complaint with CVS is that it uses the name of a file to identify its revision history, so moving or renaming a file is not possible without either interrupting its history, or renaming the history and thereby making the history inaccurate. Most post-CVS revision control systems solve this by giving a file a unique long-lived name (a sort of inode number) that survives renaming. Git does not record such an identifier, and this is claimed as an advantage.

What confirms that there is no native method to change the name of a file without losing its history, Git does not have this ability.

A solution to maintain the history and to lookup the full history,is with the following command:

git log --follow ./path/to/file
Nicolás Alarcón Rapela
  • 2,714
  • 1
  • 18
  • 29