Mic*_*ael 476 git rebase git-filter-branch
我希望在我的项目的第一次提交中更改某些内容而不会丢失所有后续提交.有没有办法做到这一点?
我不小心在源代码中的评论中列出了我的原始电子邮件,我想改变它,因为我从机器人索引GitHub收到垃圾邮件.
Von*_*onC 724
正如提到的ecdpalma 下面,GIT中1.7.12+(2012年8月)具有增强的选项--root为git rebase:
" git rebase [-i] --root $tip"现在可用于重写所有导致" $tip"到根提交的历史记录.
这个新行为最初在这里讨论:
我个人认为"
git rebase -i --root"应该只是工作而不需要"--onto",让你"编辑"甚至是历史上的第一个.
可以理解的是,没有人会感到困扰,因为人们在历史的最初阶段重写的次数要少得多.
随后是补丁.
(原答案,2010年2月)
git reset --hardRebase分支在更改提交之上,使用:
git rebase --onto <tmp branch> <commit after changed> <branch>`
Run Code Online (Sandbox Code Playgroud)诀窍是确保您要删除的信息不会被文件中其他位置的后续提交重新引入.如果您怀疑,那么您必须使用filter-branch --tree-filter以确保该文件的内容在任何提交中都不包含敏感信息.
在这两种情况下,您最终都会重写每次提交的SHA1,因此如果您已经发布了要修改其内容的分支,请务必小心.你可能不应该这样做,除非你的项目尚未公开,而其他人没有基于你即将重写的提交工作.
cmc*_*nty 81
git rebase -i允许您方便地编辑除根提交之外的任何先前提交.以下命令显示如何手动执行此操作.
# tag the old root, "git rev-list ..." will return the hash of first commit
git tag root `git rev-list HEAD | tail -1`
# switch to a new branch pointing at the first commit
git checkout -b new-root root
# make any edits and then commit them with:
git commit --amend
# check out the previous branch (i.e. master)
git checkout @{-1}
# replace old root with amended version
git rebase --onto new-root root
# you might encounter merge conflicts, fix any conflicts and continue with:
# git rebase --continue
# delete the branch "new-root"
git branch -d new-root
# delete the tag "root"
git tag -d root
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
122197 次 |
| 最近记录: |