GIT:签出替代分支时,我想清除忽略的文件 [英] GIT: When checking out an alternative branch, I want to clear ignored files

查看:95
本文介绍了GIT:签出替代分支时,我想清除忽略的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在母版中有一个结构.

Assume I have a structure in master.

d - src 
      - main ...
      - resources ...
  - target
      - xyz

不应跟踪文件xyz,因此我将其添加到.gitignore target/* 并提交结构

Files xyz should not be tracked, so I added into .gitignore target/* and commit the structure

  • git commit -m'初始结构'

我创建2个分支

  • git分支t1
  • git分支t2

并切换到t1

  • git checkout t1

我开始做一些工作,编译内容,以便填充目标. 我将更改提交给t1.

I start doing some work, compile stuff, such that target is populated. I commit my changes to t1.

  • git commit -a't1特定更改'

然后我切换到t2

  • git checkout t2

当我查看目标时,它仍然填充有创建的文件 当分支t1处于活动状态时,而我想将这些清除"

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'

我发现了一个类似的讨论,指出git的行为应与我看到的有所不同. 当我切换分支机构时,Git正在删除忽略的文件

I found a similar discussion stating that git should behave differently than I see. Git is deleting an ignored file when i switch branches

我想念什么?

弗朗西斯

推荐答案

这是设计使然. 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

git clean -xdf

更常见的是,我想扔掉未被跟踪但不会被忽略的更改.这可能是因为我正在尝试一些代码并添加了一个新的类文件.在这种情况下,我将使用:

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:

git clean -df

这将使我的输出目录保持不变.我将依靠我的开发工具来清理这些文件夹.

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.

这篇关于GIT:签出替代分支时,我想清除忽略的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆