本文介绍了为什么切换分支时Git不删除一些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常遇到过这种情况。我在一个主分支上工作,我需要测试一个插件,所以我创建了一个新的分支并检查出来。我将该插件下载到项目目录中并进行测试。然后我切换回主分支并删除我创建的分支。

最终发生的事情是该插件的文件保留在项目目录中。我想知道这是否是正常行为。为了在分支机构之间进行无缝切换,我需要做些什么?

git不会从工作中删除未跟踪的文件复制,所以除非你添加了插件的文件并在新的分支上创建了一个提交,否则git不会对你的插件文件做任何事情。



如果你想删除未跟踪文件从你的工作树上,使用 - 小心,它会从磁盘中删除任何未跟踪的文件,并且无法从中恢复(不使用反删除软件)。


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 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)

这篇关于为什么切换分支时Git不删除一些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:27