git 将分支指向新的提交

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3492536/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:29:34  来源:igfitidea点击:

Point branch to new commit

git

提问by Benjol

(This question is the opposite of this one)

(这个问题是相反这一个

How can I go from this

我怎样才能离开这里

dev            C - D
             /
master A - B 

to this?

到这个?

dev                D
                 /
master A - B - C 

I know I'm going to kick myself when I see the answer, but for the moment I'm a bit stuck...

我知道当我看到答案时我会踢自己,但目前我有点卡住了......

回答by VonC

Solution

解决方案

git checkout master
git merge C

With Cbeing the SHA1 of commit C.

随着C被提交的SHA1 C

Result

结果

                 D (dev)
                /
master A - B - C (move master HEAD)

It should be a fast-forward merge.

它应该是一个快进合并。

回答by aragaer

Necromancy, I know.

通灵术,我知道。

git branch -f master C

Will not touch current working tree at all - you can have your work in progress.

根本不会触及当前的工作树 - 您可以进行工作。