Git结帐和合并而不接触工作树 [英] Git checkout and merge without touching working tree

查看:104
本文介绍了Git结帐和合并而不接触工作树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个功能分支,我将它们合并到上游更改中,然后再推回我的更改:

  git branch feature1 
...
... [提交]
git获取原始大师
git merge fetch_head [或rebase]
... [resolve冲突]
... [构建和测试代码]

此时我希望推送我的更改。这样做的正常方式是:
$ b $ pre $ git checkout master [改变一堆工作树文件]
git合并feature1 [改变相同的文件] [

这个工作正常,但会使(date-检查)编译器认为一大堆文件是脏的,即使内容相同也需要重建。在这种情况下,有没有办法结算并合并使工作树保持不变?



类似于:

  git checkout master --merge-branch feature1 

编辑:



我只是根据定义,谈论快速前进合并不会改变文件的状态。 解决方案

这只是一个部分解决方案/解决方法。请参阅下面的@djpohly的实际答案。



首先,您可以从任何地方推送。无论你检出了什么,或者你想推送的提交是否在master中。

  git push REMOTE_REPO feature1 :master 

请参阅 git help push



提示: git push remoteRepo localRef:remoteRef



将主人带到你现在的位置,而不用摆弄你的工作副本......你可以这样强制:

 #(而仍然在feature1分支上)
git checkout -B master master / master

对主设备进行重置。即它不检查快进。


Say I have a feature branch, into which I merge upstream changes prior to pushing my changes back:

git branch feature1
... [edit my code]
... [commit]
git fetch origin master
git merge fetch_head [or rebase]
... [resolve conflicts]
... [build and test code]

At this point I wish to push my changes. The normal way of doing this would be:

git checkout master [changes a bunch of working tree files]
git merge feature1  [changes the same files right back]

This works fine, but will make the (date-checking) compiler think that a whole bunch of files are dirty and needs a rebuild even though the contents are the same. Is there a way to checkout-and-merge that leaves the working tree unchanged in this case?

Something like:

git checkout master --merge-branch feature1

EDIT:

I am only talking about fast forward merges that by definition would not change the state of the files.

解决方案

[Edit] This is only a partial solution / workaround. See the actual answer by @djpohly below.

Firstly, you can push from anywhere. Doesn't matter what you have checked out, or whether the commits you want to push are in master.

git push REMOTE_REPO feature1:master

see git help push

Hint: git push remoteRepo localRef:remoteRef

As for bringing master to where you are now without fiddling with your working copy... You can force it like so:

# (while still on feature1 branch)
git checkout -B master origin/master

But this does a hard reset on master. ie it doesn't check for fast-forward.

这篇关于Git结帐和合并而不接触工作树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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