git rebase interactive already pushed commits

孤者浪人 提交于 2019-12-06 09:44:32
dag

Changing the commit message results in changing the commit's hash value and this means all following commits have to change their hashes too (as the parent is included in the hash computation, as the message itself is too).

This is why rebasing is typically only allowed in local branches. Many or say most git remote repositories permit rewriting the pushed history as anyone could have downloaded it already and would then work on a outdated history/branch/commit.

Strategy for preventing or catching git history rewrite

However if your server does allow history rewrites (e.g. if you are the only one working on it) you may push them with --force.

As a side note see here https://stackoverflow.com/a/5668050/1756183

Edit rebase with several branches:

C1 <- C2 <- C3 (branch1)

rebasing children of C1 results in

C1 <- CR2 <- CR2 (branch1)

But if you have:

          / C4 <- C5 (branch2)
C1 <- C2 <- C3 (branch1)

rebasing will most likely lead to:

    / C2 <- C4 <- C5 (branch2)
C1 <- CR2 <- CR3 (branch1)

the reason is that C2 is still the parent of C4, the "fixed" commit CR2 is only related to the rewritten Branch branch1. If you want to "forget" C2 you have to rebase C4 on top of CR2 (you ll have to play around with rebase --onto). After that C2 is not adressed as anyone's parent or on any branch and will not be shown in the history (although it is still there until garbage collected).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!