2009-08-20 62 views
2

我必须重写我的存储库的历史记录,因为它包含一些凭证。因为我有修改根犯我跟着从Git Faq说明:Git,编辑所有分支的根提交

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 

我的问题是,虽然我在仓库中有两个分支,几个​​标签已经和我想的是我的历史改写适用于这些了。回购尚未公开,所以这不成问题。我之前询问过similar question,但在这种情况下,没有使用git rebase命令。这里是我的回购协议的基本图形:

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

它甚至有可能?

+0

可能相关:[编辑/修改/修改/更改Git中的第一个/根/初始提交?](http://stackoverflow.com/q/2119480/456814)。 – 2014-05-15 08:47:24

回答

6

使用git filter-branch而不是git-rebase。

如果你真的觉得衍合会更好,拥有现代化的git你可以使用--root选项混帐底垫。或者樱桃挑选根提交,然后重新绑定它,如果你有旧的git没有这个选项。

+0

谢谢Jakub。但我不确定'filter-branch'会如何帮助我。我必须编辑近10个文件中的代码,以便我假装第一次提交没有证书。我不知道这会怎么样,因为这些文件没有标准格式。这只是代码。我认为可以使用'--tree-filter',但似乎很难解析代码。 – 2009-08-20 18:28:30

+2

如果是这种情况,最简单的解决方案是创建一个新的空分支('git symbolic-ref HEAD refs/heads/new && rm -f .git/index'),然后在该分支上进行樱桃挑选根提交,编辑它使用'git commit --amend',然后rebase休息,或者使用'git rebase --interactive --root - to new master'。 HTH。 – 2009-08-20 22:13:32

+0

谢谢,我会尝试他们两个,虽然第二个选项似乎更容易。不胜感激。 – 2009-08-21 08:10:04