git-new-workdir:在工作树A中提交导致树B中的假冒变化 [英] git-new-workdir: Commit in working tree A causes bogus changes in tree B

查看:130
本文介绍了git-new-workdir:在工作树A中提交导致树B中的假冒变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 git-new-workdir 为一个git仓库创建两个工作树。这通常工作得很好,但是如果在两个工作树中签出同一个分支,我会在提交内容后得到一些有趣的行为:


  • I
  • 我在工作树A中提交了一些东西。



结果:


  • 工作树A中的git status显示clean(如预期的那样)
  • 工作树B中的git status突然显示要提交的更改


    所显示的变化是倒数对于
    例如,如果A中的提交添加了一行,则B中的要提交的更改
    表明该行已被删除。



    这里发生了什么?这是git-new-workdir的一个已知限制吗?
    有没有办法避免这个问题?或者我应该避免检查
    ,而同一分支在两个副本中检出?



    我也有兴趣了解这里发生了什么
    在内部(我对git的内部知识知之甚少)。

    注意:

    我发现只要在B中运行
    git reset - hard 就可以轻松解决问题,如果B在A中提交之前没有未提交的更改。

    然而,如果我在B中提交了未提交的更改,那么
    真实未提交的更改会混入来自$ b $的虚假更改b承诺,似乎没有简单的方法来解决它们。因此
    是个问题。

    解决方案

    我认为这是预期的行为。从 http://nuclearsquid.com/writings/git-new-workdir/


    在你的工作目录之一中创建一个新的提交或分支,
    在所有工作目录中立即可用。 / p>

    在A中提交更改时,该提交也可用于B.由于您刚添加到A中的行不在B中,因此您似乎从最近的提交以来进行了更改。



    我认为多工作的目的目录是同时检出不同的分支。


    I use git-new-workdir to have two working trees for one git repository. This usually works very well, but I get funny behaviour after committing something, if the same branch is checked out in both working trees:

    • I start with both working trees clean and on "master".
    • I commit something in working tree A.

    Result:

    • "git status" in working tree A shows "clean" (as expected)
    • "git status" in working tree B suddenly shows "Changes to be committed"

    The changes shown are the inverse of the commit I just made in A. For example, if the commit in A added a line, the "Changes to be committed" in B show that this line was removed.

    What is happening here? Is this a known limitation of git-new-workdir? Is there a way to avoid this problem? Or should I just avoid checking in while the same branch is checked out in both copies?

    I would also be interested in understanding what is happening here internally (I know little about git's internals).

    Note:

    I found that the problem is easy to resolve by just running git reset--hard in B, if B had no uncommitted changes prior to the commit in A.

    However, if I commit in A while there are uncommitted changes in B, the real uncommitted changes get mixed with the bogus changes from the commit, and there seems to be no easy way to disentangle them. Hence the question.

    解决方案

    I think this is the intended behavior. From http://nuclearsquid.com/writings/git-new-workdir/:

    Create a new commit or branch in one of your working directories, they’re instantly available in all working directories.

    When you commit a change in A, that commit is available to B as well. Since the line you just added in A isn't in B, it appears that you have made a change since the most recent commit.

    I think the purpose of multiple working directories is to have different branches checked out at the same time.

    这篇关于git-new-workdir:在工作树A中提交导致树B中的假冒变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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