如何使用哈希而不是分支名称进行 git rebase?
我使用 git rebase --onto target source foo 将分支 foo 从分支 source 移动到分支 target 上>。您知道是否可以使用哈希值代替分支名称(如果未给出),如下所示:git rebase --onto ab91c f4242 foo
?
作为解决方法,我临时将分支名称添加到相关提交对象中。但如果你有很多分支需要重新建立基础,这可能是一个皮塔饼。
示例情况:
° bb42a
° ab91c
° 979c2
/° fb648 foo
° f4242 --
° 333c9
git rebase --onto ...
之后
° bb42a
/° fb648 foo
° ab91c --
° 979c2
° f4242
° 333c9
背景:
如果您使用 svn-server 作为远程存储库,则所解释的问题非常常见。所有提交的对象都会被重写,因为每次 git svn dcommit
到 svn-repository 时都会添加 svn-id。这会将所有其他分支与其前master分离。
I use git rebase --onto target source foo
to move the branch foo
from the branch source
onto the branch target
. Do you know if it is possible to use hash values instead of branch names (if not given) like this: git rebase --onto ab91c f4242 foo
?
As a workaround I temporarily added branch names to the relevant commit objects. But this can be a pita if you have many branches to being rebased.
Example situation:
° bb42a
° ab91c
° 979c2
/° fb648 foo
° f4242 --
° 333c9
After git rebase --onto ...
° bb42a
/° fb648 foo
° ab91c --
° 979c2
° f4242
° 333c9
Background:
The explained problem is very common if you use an svn-server as you remote repository. All you commit objects get rewritten since the svn-id will be added every time you git svn dcommit
to the svn-repository. This detaches all other branches from their former master.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以肯定的是:
git-svn
的 警告部分 确实发出警告你:因此,您需要确保不在 SVN 同步分支中引入提交,该分支不知道该提交并会如此报告。
(在 SQ 问题“
中您有相反的情况git svn
- 在提交
中找不到
”)What is sure:
git rebase
(not agit-svn rebase
) can accept any valid commit as an argument, so hash values will work.git-svn
does warn you of:So you need to make sure to not introduce commits in a SVN-synchronized branch which wouldn't know about that commit and would report as such.
(you have the opposite case in the SQ question "
git svn
-<file>
was not found in commit<hash>
")