开发者

Why doesn't Git remove some files when I switch a branch?

开发者 https://www.devze.com 2023-01-24 09:04 出处:网络
I have had this happen to me often. I am working on a master branch and I need to test a plugin, so I create a new branch and check it out. I download the plugin into the project directory and test it

I have had this happen to me often. I am working on a master branch and I need to test a plugin, so I create a new branch and check it out. I download the plugin into the project directory and test it out. Then I switch back to the master branch and delete the branch I had created.

What ends up happening is the files of the plugin remain in the project directory. I'm wondering if this is normal behavior. What do I have to do in order开发者_StackOverflow中文版 to have a seamless switch between branches?


git will not remove untracked files from your working copy, so unless you added the files of the plugin and created a commit on the new branch git will not do anything to your plugin files.

if you want to remove untracked file from your working tree, use git clean – be careful, it will remove any untracked file from disk and there's no way to recover from that (without using undelete software)


If you are switching back and forth between branches where the directory structures are different, and you find that there are some artifacts left over, you might need to run:

git clean -df

This will "delete" "force". You will loose ALL untracked files, I think this might be one step away from:

git reset --hard


try checkout -f

see git --help checkout:

Proceed even if the index or the working tree differs from HEAD. This is used to throw away local changes.

0

精彩评论

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

关注公众号