[英]Pushing Only Recent History to a New Git Repo
I have a legacy repository that has been corrupted through some misdirection of LFS and files that are no longer accessible.我有一个遗留存储库,该存储库已因 LFS 的误导和不再可访问的文件而损坏。 The result is that it requires access to files that no longer exist to push to a new repository or major surgery on the history that seems too difficult/risky that this time.
结果是它需要访问不再存在的文件以推送到新的存储库或对历史进行重大手术,这一次似乎太困难/太冒险了。 I would like to attempt to create a new repository and push only recent history to avoid the old and bad commits.
我想尝试创建一个新的存储库并仅推送最近的历史记录以避免旧的和错误的提交。 Say, all commits since a certain date or from a certain commit.
比如说,自某个日期或某个提交以来的所有提交。 Is this possible?
这可能吗?
Why not just delete everything before the first "good" commit?为什么不在第一次“好”提交之前删除所有内容?
One easy way:一种简单的方法:
git rebase -i --root
You are shown a list of all commits in reverse order from the start, eg从一开始就以相反的顺序向您显示所有提交的列表,例如
pick aa48e9c start
pick e10b625 middle
pick 6691860 finished up
Let's say we want to get rid of "start" and "middle" but keep "finished up".假设我们想去掉“start”和“middle”,但保留“finished up”。 So just delete those two lines and save.
所以只需删除这两行并保存。
pick 6691860 finished up
An artificial empty first commit will be created, but the bad commits will be gone.将创建一个人为的空第一次提交,但错误的提交将消失。 There might be some conflicts to work out but it shouldn't be difficult.
可能会有一些冲突需要解决,但应该不难。
Perhaps you could try git rebase --onto <sha1> <sha2> <sha3>
(see this link ) functionality where也许您可以尝试
git rebase --onto <sha1> <sha2> <sha3>
(请参阅此链接)功能,其中
So all in all something like this:所以总的来说是这样的:
newRepo
newRepo
的新本地存储库mkdir newRepo
cd newRepo
git init
newRepo
just to initialize master branchnewRepo
中创建一个初始提交只是为了初始化 master 分支touch temp_file_for_initial_commit
git add .
git commit -m "Initial commit of new corruption-free repository"
oldRepo
oldRepo
获取所有历史记录git add origin "/path/to/oldRepo" # notice it could just be a path to the local repo
git fetch origin
git rebase --onto
to copy old range of valid commits to new repogit rebase --onto
将旧范围的有效提交复制到新的 repogit rebase --onto master <sha of parent of first commit> <sha of latest commit>
git checkout -b latest-history-on-new-repo
git remote remove origin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.