我有一个网站,当我开始开发它时,我已经克隆了Laravel github存储库及其所有提交内容。现在我要删除所有原始提交,仅保留我的。有什么办法吗?我尝试了git rebase,但是它需要手动选择所有6k提交并从最新版本中删除提交。 (我需要最老的)。
最佳答案
我认为您可以通过签出特定的提交,在该提交处创建一个孤立的分支,然后重新部署到该分支上来做到这一点。
在第一次提交之前签出提交git checkout <commit hash before your first commit>
创建一个孤立的分支。索引将包含处于该状态的文件,但是将没有提交历史记录。git checkout --orphan foo
提交压缩的更改git commit -m 'Squashed!'
结帐您的主要分支git checkout <original branch name>
重新建立新的压缩分支。git rebase foo
我在master
上使用5次提交的存储库对此进行了测试:
* 40f82e6 - 5
* 78deb2c - 4
* aff34f8 - 3
* 15cd469 - 2
* 6e420cb - 1
让我们挤压前三个(输出缩写):
$ git checkout aff34f8
Note: checking out 'aff34f8'.
HEAD is now at aff34f8 3
$ git checkout --orphan foo
Switched to a new branch 'foo'
$ git commit -m 'Squashed!'
[foo (root-commit) 933b62d] Squashed!
$ git checkout master
Switched to branch 'master'
$ git rebase foo
First, rewinding head to replay your work on top of it...
Applying: 1
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: 2
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: 3
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
Applying: 4
Applying: 5
进行此更改后,master现在看起来像这样:
* 5d908c9 - 5
* 477ee53 - 4
* 933b62d - Squashed!
关于git - 压缩约6k提交成一个,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/60547591/