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

Ion*_*tan 2 git

我必须重写我的存储库的历史记录,因为它包含一些凭据.因为我必须修改root提交,所以我遵循Git Faq的指示:

git rebase -i允许您方便地编辑除根提交之外的任何先前提交.以下命令显示如何手动执行此操作.

# 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
Run Code Online (Sandbox Code Playgroud)

我的问题是,我已经在存储库中有两个分支和几个标签,我希望我的历史记录重写也适用于那些.回购还没有公开,所以这不是问题.我以前问了一个类似的问题,但在那种情况下git rebase没有使用该命令.这是我的回购的基本图表:

+  master branch
|
|   + topic branch
|   |
|   |
+---+
|
|
|
+  TAG
|
+  Initial commit, the commit I'd like to amend for all branches
Run Code Online (Sandbox Code Playgroud)

它甚至可能吗?

Jak*_*ski 6

使用" git filter-branch "代替git-rebase.

如果你真的,真的觉得rebase会更好,使用现代git你可以使用--rootgit-rebase选项.或者樱桃挑选root提交,然后在它上面进行rebase,如果你有没有这个选项的旧git.

  • 如果是这种情况,最简单的解决方案是创建新的空分支(`git symbolic-ref HEAD refs/heads/new && rm -f .git/index`),并将樱桃选择root提交到该分支并编辑它使用`git commit --amend`,然后使用rebase rest,或使用`git rebase --interactive --root --onto new master`.HTH. (2认同)