简体   繁体   中英

BFG restore deleted files in history

BFG was used to delete files from history. During this process a deleted-files.txt was written.

A former clone still contains the deleted files... git cat-file -p xxx (xxx as stated in deleted-files.txt)

Is there a way to restore the original history? Means add all versions that where deleted by using BFG? Simple undo everything BFG has done.

There is no simple method except this one: If you have the former clone, just use it.

Why this is this way

The history in any Git repository consists of the commits in that repository.

Deleting a file is technically impossible. BFG doesn't do that, and neither does git filter-branch . Instead, these commands make a new series of commits that are somewhat like the old commits, but simply lack the file. Then they change the branch names (and, optionally, additional references) so that instead of remembering the old commits, those branch names remember the new commits. Et voila, you have a new repository, no longer compatible with the old one, with new commits that form a new and different history.

Both commands also produce a mapping file relating the old commits and the new commits. The BFG retains this map file (which is the right thing to do), while git filter-branch throws it away at the end of the filtering process (which is the wrong thing to do). If you have the map, you have a way—not a simple one, but a way —to correlate the new history with the old history.

This would allow you to do what you are suggesting. However, to make it work, you must have access to the old repository ... in which case, you might as well just use the old repository.

What if you have new commits since then?

The only reason you might not want to just switch back to the old repository is if you have made new commits since you did the conversion.

If you can identify the specific new commits, and you have the old repository, you can convert each of the new commits to a patch or a git merge command, and apply that patch or run that git merge . This is not simple, but would allow you to copy the "new repo only" commits back into the old repository. There is more than one way to do this, with various advantages and drawbacks, but it too is not going to be simple—and in any case it depends on being able to list these "new since filtering" commits.

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