简体   繁体   English

拉/合并未提交的更改

[英]Pull/merge uncommitted changes

I have two git working directories. 我有两个git工作目录。 As sometimes happens, I've made some changes in the wrong directory and would like to move those to the other one now. 有时候,我在错误的目录中做了一些更改,现在想将它们移到另一个目录中。 That is, I would like to merge/pull the uncommitted changes from one place to the other. 也就是说,我想将未提交的更改从一个位置合并/拉到另一个位置。

In bzr I would use merge with the --uncommitted option, but I've been unable to find a git equivalent. 在bzr中,我会使用带有--uncommitted选项的merge,但是我一直找不到等效的git。

Pushing and pulling inherently works on commits, so I don't think there's any way to do that, specifically. 推和拉本质上对提交起作用,所以我认为没有任何方法可以做到这一点。

However, you could just create a temporary branch ( git checkout -b tmp ), commit to that, pull it to the other repository ( git pull $OTHER tmp ) and then either continue from that commit, or revert HEAD to the latest commit while keeping the changes to the working tree ( git reset HEAD^ ) and go on working on them that way. 但是,您可以只创建一个临时分支( git checkout -b tmp ),提交该分支,将其拉到另一个存储库( git pull $OTHER tmp ),然后从该提交继续,或者将HEAD还原为最新提交保留对工作树( git reset HEAD^ )的更改,然后继续进行修改。

Edit: Perhaps even more importantly, however: Are you sure you want to have two separate working directories? 编辑:也许更重要,但是:您确定要拥有两个单独的工作目录吗? I can see that being useful in eg Mercurial or SVN (I haven't used Bazaar, so I can't speak for it), but in Git, you would normally use branches and stashes instead. 我可以看到它在Mercurial或SVN(我没有使用过Bazaar,所以我不能说它)中很有用,但是在Git中,通常会使用分支和隐藏。

A low-tech solution is simply to use git diff : 一个技术含量低的解决方案就是使用git diff

$ cd wd_1
$ (cd ../wd_2 ; git diff -p) | patch -p1

You can the git reset in the other working directory. 您可以在其他工作目录中进行git reset

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

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