使用未提交的自动生成的更改切换 GIT 中的分支

发布于 2024-12-28 08:59:27 字数 346 浏览 4 评论 0原文

我正在尝试切换 GIT 中的本地分支,但一些自动生成的、忽略的和未提交的文件阻止了它。有没有办法让这些文件不阻止我切换分支?

我有一个共同的工作流程。我有一个开发分支,其中有一些我从源代码本地生成的 .class 文件。 .class 文件不在存储库中,它们将被忽略。当我更新本地开发分支时,我生成所有类文件。一切都很好。

当我尝试切换分支时,我会收到关于这些类文件中所有未提交的更改的警告。我可以通过使用强制开关从命令行切换分支来解决这个问题,但这看起来很愚蠢。有什么办法让 GIT 知道它真的不应该关心这些文件/文件夹吗?

我的团队正在使用 Eclipse 和 Egit。任何帮助将不胜感激。

谢谢, 大卫·R

I'm trying to switch local branches in GIT but some auto-generated, ignored and uncommitted files are preventing it. Is there a way to have these files not prevent me from switching branches?

I have a common workflow. I have a development branch which has some .class files that I generate locally from source. The .class files are not in the repo and they are ignored. When I update my local development branch I generate all the class files. Everything is good.

When I try to switch branches I get warned about all my uncommitted changes in these class files. I can get around this by switching branches from the command-line with the force switch but this seems silly. Is there any way to let GIT know it really shouldn't be concerned with these files / folders?

My team is using Eclipse and EGit. Any help would be appreciated.

Thanks,
David R

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

您的其他分支可能已经提交了这些内容,这些内容将与您工作目录中的内容发生冲突。您可以执行以下两件事之一:

git clean -xdf # to get rid of the untracked files and then you can switch

git clone this-repo # to another place
git checkout -t origin/other-branch 
# clean up the files that should be ignored
git add -A && git commit -m "fixed ignored files" && git push -f
# go back to the original repo
git checkout other-branch # should work now

Your other branch probably has those committed and these will clash with what you have in your working dir. You can do one of 2 things:

git clean -xdf # to get rid of the untracked files and then you can switch

or

git clone this-repo # to another place
git checkout -t origin/other-branch 
# clean up the files that should be ignored
git add -A && git commit -m "fixed ignored files" && git push -f
# go back to the original repo
git checkout other-branch # should work now
岁月蹉跎了容颜 2025-01-04 08:59:27

如果您确实不想提交这些文件,请将它们添加到本地 .gitignore 文件中。

在 python 项目中,我的 .gitignore 看起来像这样:

.*~
*~
*.py[co]

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

还有一个流行的 git 树适用于各种编程语言和环境的 .gitignore 文件。

如果您想保留您的工作,但跳到另一个分支,也许是为了快速发布错误修复版本,
git 存储
是你的朋友吗?

git stash save "meaningful message"

将保存存储并允许您切换分支

git stash list

将列出各种存储

git shash pop <stash id>

将恢复存储

If you really don't want to be committing these files, add them to a local .gitignore file.

On a python project, this is what my .gitignore looks like this:

.*~
*~
*.py[co]

# Unit test / coverage reports
.coverage
.tox

#Translations
*.mo

There is also a git tree of popular .gitignore files for various programming languages and enviroments.

If you want to retain your work but hop of to another branch perhaps to do a quick bug-fix release,
git stash
is your friend there.

git stash save "meaningful message"

will save the stash away and allow you to switch branches

git stash list

will list the various stashes

git shash pop <stash id>

will restore a stash

⊕婉儿 2025-01-04 08:59:27

请注意,那些未提交的文件仍然是一个问题,最近的 EGit2.0 现在< a href="http://wiki.eclipse.org/EGit/New_and_Noteworthy/2.0#Stash_Support" rel="nofollow noreferrer">支持隐藏

Egit stash

分支结果对话框中有一个新的存储选项
这允许快速隐藏任何阻止分支检出的冲突更改

Note that is those uncommitted files are still an issue, the recent EGit2.0 now supports stash.

Egit stash

And there is a new stash option in branch result dialog.
This allows to quickly stash any conflicting changes that are preventing a branch from being checked out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文