简体   繁体   English

如何将旧版本合并到git中的分支负责人?

[英]How to merge old version to head of a branch in git?

My repository has 2 branches, master and mybranch .我的存储库有 2 个分支, mastermybranch I've commited many times into mybranch , realized that many of my changes were not what I wanted.我已经多次提交mybranch ,意识到我的许多更改不是我想要的。

Thus, I did a git checkout of an old commit on* mybranch* using因此,我对 * mybranch* 上的旧提交进行了git checkout使用

git checkout 02c383

I want this old commit to be the HEAD of mybranch .我希望这个旧提交成为mybranchHEAD How do I do this?我该怎么做呢?

When I look at my branches, I see:当我查看我的分支时,我看到:

$ git branch
*(detached from numbershere)
mybranch
master
git checkout mybranch
git reset --hard 02c383

After this, mybranch will be moved to point to 02c383 .在此之后, mybranch将被移动到指向02c383

You can reset the current branch to a different commit with您可以将当前分支重置为不同的提交

git reset --hard <ref>

In your example, this translates to在你的例子中,这转化为

git reset --hard 02c383

Beware that当心

  • you should avoid doing such things (esp. when mybranch is already used by others)你应该避免做这样的事情(尤其是当mybranch已经被其他人使用时)
  • getting back to the previous commit to which mybranch pointed before (which is now a dangling commit becomes a bit tricky, if you can't remember that SHA.又回到了以前的承诺,这mybranch之前指出的(现在是一个悬空提交变得有点棘手,如果你不记得SHA。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM