将其他分支重置为当前分支而无需签出 [英] Reset other branch to current without a checkout

查看:46
本文介绍了将其他分支重置为当前分支而无需签出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Git工作流程编写一些脚本.

I'm writing some scripts for my Git workflow.

我需要将其他(现有)分支重置为当前分支,而无需检出.

I need to reset other (existing) branch to the current one, without checkout.

之前:

 CurrentBranch: commit A
 OtherBranch: commit B

之后:

 CurrentBranch: commit A
 OtherBranch: commit A

等同于

 $ git checkout otherbranch 
 $ git reset --soft currentbranch
 $ git checkout currentbranch

(注意--soft:我不想影响工作树.)

(Note --soft: I do not want to affect working tree.)

这可能吗?

推荐答案

您描述的工作流程并不相同:执行reset --hard时,您会丢失工作树中的所有更改(您可能希望将其更改为reset --soft ).

The workflows you describe are not equivalent: when you perform reset --hard you lose all the changes in the working tree (you might want to make it reset --soft).

您需要的是

git update-ref refs/heads/OtherBranch refs/heads/CurrentBranch

这篇关于将其他分支重置为当前分支而无需签出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆