GIT:检查替代分支时,我想清除忽略的文件
假设我在 master 中有一个结构。
d - src
- main ...
- resources ...
- target
- xyz
文件 xyz 不应该被跟踪,所以我添加到 .gitignore target/* 并提交结构
- git commit -m '初始结构'
我创建 2 个分支
- gitbranch t1
- gitbranch t2
并切换到 t1
- git checkout t1
我开始做一些工作,编译东西,这样目标就被填充了。 我将更改提交给 t1。
- git commit -a 't1 具体更改'
然后我切换到 t2
- git checkout t2
当我查看目标时,它仍然填充有创建的文件 当分支 t1 处于活动状态时,虽然我希望将这些“清除”,但
我发现了一个类似的讨论,指出 git 的行为应该与我看到的不同。 当我切换分支时,Git 正在删除忽略的文件
我缺少什么?
弗朗西斯
Assume I have a structure in master.
d - src
- main ...
- resources ...
- target
- xyz
Files xyz should not be tracked, so I added into .gitignore target/*
and commit the structure
- git commit -m 'initial structure'
I create 2 branches
- git branch t1
- git branch t2
and switch to t1
- git checkout t1
I start doing some work, compile stuff, such that target is populated.
I commit my changes to t1.
- git commit -a 't1 specific changes'
then I switch to t2
- git checkout t2
When I look into target, it is still populated with the files created
when branch t1 was active, while I would like to have these 'cleared out'
I found a similar discussion stating that git should behave differently than I see. Git is deleting an ignored file when i switch branches
What am I missing ?
Francis
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是设计使然。 Git 不会触及工作文件夹中未跟踪的文件。如果你想清理未跟踪的文件,你可以使用
更常见的方式,我想扔掉未跟踪但未忽略的更改。这可能是因为我正在试验一些代码并添加了一个新的类文件。在这种情况下,我将使用:
这将使我的输出目录保持原样。我会依靠我的开发工具来清理这些文件夹。
您可以使用该钩子,但这不是一个好的解决方案,因为它更难在团队中共享。
This is by design. Git will not touch files that it is not tracking in the working folder. If you want to clean the untracked files you can use
More commonly, I want to throw away changes that are not tracked but not ignored. This may be because I was experimenting with some code and added a new class file. In this case I would use:
This would leave my output directories as is. I would rely on my development tools to clean these folders instead.
You could use the hook, but that's not a good solution as it is harder to share across a team.
您可以添加一个
post-checkout
挂钩来清理被忽略的文件:You can add a
post-checkout
hook which cleans ignored files:您链接的问题正在讨论在一个分支中跟踪并在另一个分支中忽略的文件。您正在谈论未在任何分支中跟踪的生成文件。由于 git 不跟踪它们,因此不会对它们做任何事情。
The question you linked is talking about a file that's tracked in one branch and ignored in another. You're talking about generated files that aren't tracked in any branches. Since git isn't tracking them, it won't do anything to them.