git checkout remote branch shows extraneous files?

前提是你 提交于 2020-01-14 04:20:28

问题


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\TickZoom\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


回答1:


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!




回答2:


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



来源:https://stackoverflow.com/questions/1753467/git-checkout-remote-branch-shows-extraneous-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!