Replaced BFG text, and now it shows that my fork is several hundred locked forward / backward

I recently forked a project and after several dozen commits I noticed that there was some confidential information that I wanted to delete from the file. Wanting to remove this, either by canceling only my commits for this file, and changing the changes as one, or possibly replacing the text string, I found BFG. I ran:

bfg --replace-text replacements.txt -fi file . 

and then 'git reflog expire ...', as suggested by the BFG output. After the force is pressed on the remote, my plug says:

 This branch is XXX commits ahead, XXX commits behind โ€ฆ:master. 

Too late, perhaps for cancellation, if I do not want to update and add my changes as a single commit. Is there any fix?

edit: My situation is very similar to the one here:

Git Merge duplication after inefficient use of BFG

Journal

Git doesn't show anything bad, but using other applications, I see that the whole story has duplicates for each commit. Github Desktop also shows two branches: master and originalproject / master, and I remember that it only showed the master. I don't know enough about git to figure out the next step. An attempt to use git reset --hard master xxxx using the commit id from the log says: "Cannot perform hard reset using paths."

+1
source share
1 answer

To understand the reason for this, you need to understand the implications of rewriting history in Git. BFG is a tool that overwrites Git, captures and therefore the history of your project.

Git tracks commit through commit hashes. A concat hash is calculated in several ways: the hash of the parent, the contents of the repo (tree hash), author, committer, date / time of the commit, commit message, etc. If any of these changes changes, for example, the contents of the file, parent commit, then the hash commit will change when this message is overwritten during cleanup. Starting with the first such commit you rewrite, each subsequent commit will be different and have a different hash, regardless of whether it was rewritten or not, since the parent hash will differ from this point forward.

In a repo universe cloned / forked from an upstream repo, Git can determine where divergence occurred by comparing a common / new commit (hashes). Since you rewrote the story in your clone, it now diverges from the upstream point of the first commit that you rewrote. This is what Git tells you when explaining your branch forward / backward.

If you only rewrite, you do it in your own fork, since you are forked and you have not merged, then this is unlikely to be a big problem. If this is not the case, then if you canโ€™t get the repository back up the river to rewrite your story, then you will always have a potentially big discrepancy.

As Jonathan Brinkโ€™s commentary suggests, itโ€™s best to repackage your peeled commits to the youngest shared commit.

+1
source

Source: https://habr.com/ru/post/971686/


All Articles