简体   繁体   中英

GIt: Removed several files from repository with BFG and there are enormous commit diffs

I recently removed several large files from a repository using BFG --delete-files , and the output appeared to be what I expected. The correct files and sizes were reported as deleted from the repo and the local size reflects these removals.

However, when I upload and compare to master, it reports that there is a huge difference and it affects several hundred commits. I'm not sure what to make of this or how to understand it; it is too much to go through. I understand removing the files will restructure the repo, but how can I be sure what was intended actually happened in the diff?

It depends on the nature of the diff seen in all those files.

For instance, if they are EOL differences (end-of-lines), that could means the BFG commit-rewritten process was done locally with a config core.autocrlf which might have change eol for all the files (in addition of removing some of them).
Once pushed, all the other files would be shown as "different".

It's caused by java -jar bfg.war --delete-files filename will delete the the specified file from the whole commit histories for all branches, but you only push one branch to remote .

Assume the commit history as below before using BFG to delete files as below:

…---A---B---C---D  master, origin/master
         \
          E---F  mybranch, origin/mybranch

When you compare master branch with mybranch , the related commits are C , D , E and F .

And assume the delete-files is test.txt , and it only exist in commit B and E . When you execute

java -jar bfg.war --delete-files test.txt

The commit history will be:

…---A---B'---C'---D'  master, origin/master
         \
          E'---F'  mybranch, origin/mybranch

Note: it rewrite the commits not only for local branches ( master and mybranch ), but also re-point the tracking branches ( origin/master and origin/mybranch ).

If you do git fetch after that, you will find the local branches with their tracking branches are diverged:

        E---F    origin/mybranch
       /
      B---C---D  origin/master
     /     
…---A---B'---C'---D'  master
         \
          E'---F'  mybranch

While if you only force push mybranch to remote repo (not force push master branch), the commit history on remote repo will be:

      B---C---D  master
     /     
…---A---B'---E'---F'  mybranch

So when you compare mybranch with master branch again, the relate commits will contains B , C , D , B' , E' and F' .

And if you also force push local master btanch to remote, the count of related commits should be the same when you compared when using BFG.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM