git 更改分支的起源(rebase)

标签 git branch rebase

如果我有以下内容:

A---B---C-----D--   branch dev
     \--C'-E-/      branch test

我做得不好:C 和 C' 几乎是相同的提交,如果我可以让分支 test 从 C 而不是 B 开始会更有意义。

我该怎么做?我猜是 rebase,但我不确定如何使用它,thx

编辑:不清楚 我想要什么:

A---B---C-----D--   branch dev
         \-E-/      branch test

A--B--D--E--D 如果不可能的话

最佳答案

您可以在临时分支(由 C 制作)之上对其进行 rebase
参见 git rebaseRebasing , 加上 git branch .

git branch tmp C
git checkout test

# rebase the current branch (test) on top of tmp
git rebase tmp  

git branch -d tmp

那应该给你:

A---B---C-----D--       branch dev
         \--C''-E'-/      branch test

我离开了 C'(此处为 C''),因为 C' 与 C 不完全相同。
但是作为ams评论,如果你需要 C' 走了,你会

git rebase -i tmp

这将使您获得一个交互式 rebase,允许完全删除 C',仅在 之上重播 E C.

关于git 更改分支的起源(rebase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10976938/

相关文章:

git safe rebase 或 "try rebase, fallback to merge"

git - 做 rebase 时我应该在哪个分支?

git - 通过 HTTP 转储远程基于 Git 的 SVN 存储库时出错

windows - 是否可以使用 winmerge 从 cygwin 查看 git 差异?

git - 如何使用 Github Actions 查看最新提交?

git - 存储在 refs/heads 之外的 ref 是否可以被视为分支并作为普通分支 check out 和工作?

api - 找到合并分支的tfs路径

git - Docker:如何从 Github 存储库上的非主分支构建镜像

ruby-on-rails - ENOTFOUND : getaddrinfo ENOTFOUND api. heroku.com api.heroku.com:443 heroku 创建错误

git - `git branch --list` 返回文件?