简体   繁体   English

Git,为所有分支编辑根提交

[英]Git, edit root commit for all branches

I have to rewrite the history of my repository because it contains some credentials. 我必须重写存储库的历史记录,因为它包含一些凭据。 As I have to amend the root commit I followed the instructions from Git Faq : 由于必须修改root提交,因此我遵循了Git Faq的指示:

git rebase -i allows you to conveniently edit any previous commits, except for the root commit. git rebase -i允许您方便地编辑除根提交以外的所有以前的提交。 The following commands show you how to do this manually. 以下命令显示如何手动执行此操作。

 # tag the old root git tag root `git rev-list HEAD | tail -1` git checkout -b new-root root # edit... git commit --amend # check out the previous branch git checkout @{-1} # replace old root with amended version git rebase --onto new-root root # cleanup git branch -d new-root git tag -d root 

My problem is though that I have two branches and several tags already in the repository and I'd like that my history rewrite to apply to those too. 我的问题是,尽管我在存储库中已经有两个分支和几个标签,但我希望重写历史记录以将其应用于这些对象。 The repo isn't public yet, so that wouldn't be a problem. 回购尚未公开,所以这不是问题。 I've asked a similar question before, but in that case the git rebase command was not used. 我之前曾问过类似的问题 ,但在这种情况下,不使用git rebase命令。 Here's a basic graph of my repo: 这是我的仓库的基本图表:

+  master branch
|
|   + topic branch
|   |
|   |
+---+
|
|
|
+  TAG
|
+  Initial commit, the commit I'd like to amend for all branches

Is it even possible? 可能吗

Use " git filter-branch " instead of git-rebase. 使用git filter-branch代替git-rebase。

If you really, really feel that rebase would be better, with modern git you can use --root option to git-rebase. 如果您真的真的觉得rebase会更好,使用现代git可以使用--root选项来git-rebase。 Or cherry-pick root commit, and then rebase on top of it, if you have older git that doesn't have this option. 或者,如果您有没有此选项的较旧git,则可以选择root提交,然后在其基础上重新构建。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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