开发者

git checkout remote branch shows extraneous files?

master branch has these files and folders (simplified):

C:\Local\TickZoom\Project>ls
file.txt         name.txt      public

public branch is tracking a vendor repository and has been subtree merged as public folder in master branch above. public has three folders only (simplified):

C:\Local\TickZoom\Project>ls
platform  providers  www

When switching from public to master it behaves correctly.

However, when switching from master to public, an odd thing happens. It has all the files and folders of both combined:

C:\Local\Ti开发者_StackOverflowckZoom\Project>git checkout public

C:\Local\TickZoom\Project>ls
file.txt  name.txt   public
platform  providers  www

However, checking git status says nothing has changed.

I discovered that 'git reset --hard' fixes public back.

CLUE: It seems that this only happens after making a new commit to master. Does git do some kind of automatic merge?

After 'git reset --hard', the checkout to master and back to public work fine, even if repeatedly.

The first, I thought it was fixed but it occurred again the next time I made a change. Let me try that one more time now to make sure...

Now, I can't reproduce it. But it did happen twice.

One other CLUE is that the first time I did a git reset --hard it complained about files being locked by processes.

After the offending programs were closed, the git reset --hard succeeded and then the checkout worked between the two branches.

So does the checkout get confused by files being locked and "silently" fail? It would be better, it that's the problem to fail the same way git reset --hard does than just reporting success and having a jumbled workspace.

Any other wisdom or options to set on git checkout to avoid this will be appreciated.

Wayne


You can clean all untracked files using:

git clean -dfx

Be sure there really aren't any untracked files that you want to keep before you run this command!


use this to resolve

git clean -f -d -X

This cleans out only files ignored by your .gitignore and all empty directories that contain them.

I now do this in a script before checkout of branches that are from totally different repositories.

This isn't such an issue when switching branches between the same software.

Wayne

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜