GIT:在new / dirty / dev分支中提交对旧/安全分支的更改,而不检出或丢失未分离的数据 [英] GIT: commit changes to old/safe branch while in new/dirty/dev branch without checking out or losing unstaged data

查看:122
本文介绍了GIT:在new / dirty / dev分支中提交对旧/安全分支的更改,而不检出或丢失未分离的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我开始开发一些实验之前,我创建了一个新分支。我通常会忘记(这不是问题),但现在我事先做好了。

此后我更新了3个文件。


  • 2中只有我不想提交给安全分支的实验性更改。

  • 1中只有安全(次要)更改,我确实要将其提交给安全分支。我很满意这些最新的变化,以及(但不是)承诺给新的分支。



有可能 - 我敢肯定它是 - 快速地从我的(脏的)工作目录提交一些未分离的,未提交的更改到一个旧的,安全的分支?

唯一的我可以想到的是切换分支(没有签出),在1个文件中提交更改并切换回来,但我不知道当切换回脏分支时会发生什么变化(它们是否仍然在那里,或者它们是否在那里'消失'由于提交?)...

我确定GIT有这样美丽的东西,但GIT有这么多,我找不到完全一样的东西。

(我一直在使用这个'手册'寻求帮助,但我不确定那里是否有同样的东西,如果是(并且你愿意扫描这个东西),请让我知道,所以我知道下一次看哈rder。)



谢谢!现在我只是随便修改一张纸以后再提交给安全分支。

情况是

  x  -  x  -  x(安全)
\

你想去

  x  -  x  -  x  -  a(仅在安全banch中提交)
\
b,c(b和c提交exp分支)

您可以:

  git在exp分支中添加
git commit -m#,喘气!
git stash save#保存正在进行的exp其余工作
git checkout master
git合并exp#快进合并

x - x-- x - a(safe,exp)
\
[b,c](stashed)

git branch -f exp HEAD〜1#将分支exp重置为' a'
git checkout exp
git stash pop
git add -A
git commit -m...

x - x- -x - a(仅在安全banch中提交)
\
b,c(在exp分支中提交的b和c)


I created a new Branch before I started dev on something experimental. I usually forget that (which isn't a problem), but now I did it beforehand.
Since then I have updated 3 files.

  • In 2 are only experimental changes that I DON'T want committed to the safe branch.
  • In 1 are only safe (minor) changes that I definitely DO want committed to the safe branch. I'm fine with these last changes to be committed to the new branch as well (but rather not).

Is it possible - I'm sure it is - to (quickly) commit a few unstaged, uncommitted changes from my (dirty) working dir to an old, safe branch?

The only thing I can think of is switching branches (without checkout), commit the changes in 1 file and switch back, but I don't know what will have happened to the changes when switched back to the dirty branch (are they still there or did they 'vanish' due to the commit?)...

I'm sure GIT has something beautiful for this, but GIT has so much, I can't find the exact same thing.
(I've been using this 'manual' for help but I'm not sure the same exact thing is in there. If it is (and you're willing to scan the thing), please let me know, so I know next time to look harder.)

Thanks! For now I'll just keep a piece of paper handy with changes 'to commit to safe branch later'.

解决方案

So your situation is

x--x--x (safe)
       \
        <a,b,c> (3 private evolutions in exp branch)

And you want to go to

x--x--x--a (a committed only in safe banch)
       \
        b,c (b and c commited in exp branch)

You could:

git add a
git commit -m        # in exp branch, gasp!
git stash save       # save the rest of the exp work in progress
git checkout master
git merge exp        # fast-forward merge

x--x--x--a (safe,exp)
          \
           [b,c] (stashed)

git branch -f exp HEAD~1  # reset branch exp to before 'a'
git checkout exp
git stash pop
git add -A
git commit -m "..."

x--x--x--a (a committed only in safe banch)
      \
        b,c (b and c commited in exp branch)

这篇关于GIT:在new / dirty / dev分支中提交对旧/安全分支的更改,而不检出或丢失未分离的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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