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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…