git - 如何使用散列而不是分支名称进行 git rebase?

标签 git hash branch git-svn 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-id 到 svn-repository。这会将所有其他分支从它们以前的 master 中分离出来。

最佳答案

确定的是:

  • 一个git rebase (不是 git-svn rebase )可以接受任何有效的提交作为参数,因此哈希值将起作用。
  • caveat sectiongit-svn确实警告你:

avoid all git clone/pull/merge/push operations between git repositories and branches.
The recommended method of exchanging code between git branches and users is git format-patch and git am, or just 'dcommit’ing to the SVN repository.

因此,您需要确保不要在 SVN 同步分支中引入提交,SVN 同步分支不会知道该提交并会这样报告。
(你在 SQ 问题“ git svn - <file> was not found in commit <hash> ”中有相反的情况)

关于git - 如何使用散列而不是分支名称进行 git rebase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6519400/

相关文章:

git - intellij idea : how to diff contents of a folder (recursively) against latest (or earlier) revision in SCM repo (e. g., Git ?)

git - 如何在 bash 别名中扩展命令?

git - Visual Studio git.exe的位置在哪里?

git - npm 安装 git 子模块的依赖项

git - git 分支后的# 标签是什么意思

git - 如何成功地保持 master 和 development 分支同步?地理信息系统

php - 在php中散列一个字符串

javascript - 使用 JS Crypto 库计算大文件 MD5 时浏览器卡住(OOM?)

python - 将 python 2 检查哈希转换为 python 3

git - 开发和发布分支的版本控制(git-flow)