git - (git) : How to bring specific commit from upstream branch?

标签 git branch commit rebase

我有这个(git repo):

A--B--C--D ->master
   \--E    ->dev

我只想将提交 D 带到分支 dev (D 不依赖于 C ), 所以:

A--B--C--D  ->master
   \--E--D' ->dev

但是 D' 不应该在 merge 后添加到 master 中:

A--B--C--D--E' ->master
   \--E--D'/   ->dev

这是因为我只想带来一个文件更新,而不必用 C(代表另一个大 merge )添加的新文件污染 dev
我猜我需要使用 git rebase,但我猜不出如何使用。

最佳答案

您想使用 git cherry-pick .我假设你的 Remote 被命名为“origin”(但用远程仓库的真实名称代替“origin”)。我假设您有两个本地分支,它们也分别命名为 masterdev。我假设提交 D 在 origin/dev 上。您可以通过以下方式挑选 D:

$ git fetch origin             # Assuming the upstream remote's name is "origin"
$ git checkout dev             # Check out your local "dev" branch
$ git cherry-pick $COMMIT_D    # Replace "COMMIT_D" with the hash for commit D

现在您将只有 dev 中提交 D 的更改。

关于git - (git) : How to bring specific commit from upstream branch?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2273133/

相关文章:

git - "git fetch --tags"是否包括 "git fetch"?

git - 跟踪 .git/hooks 中钩子(Hook)的变化

git - 在 git merge 时总是忽略某个提交

version-control - Mercurial:在分支之间 merge ......向后?

git - 大量 git commit 压缩

svn - 我正在尝试提交大量源代码。为什么 txn Prop 文件丢失

git 搁置到远程仓库

git - 编辑 git 提交消息时自动进入插入模式

c++ - git 和 C++ 工作流程,如何处理对象和归档文件?

git - 每个环境使用分支时避免冲突的分支流程应该是什么