GIT - 当没有提交 - 当文件处于gitignore时,无法检出到其他分支 [英] GIT - Fail to checkout to other branch when nothing to commit - when file is in gitignore

查看:1075
本文介绍了GIT - 当没有提交 - 当文件处于gitignore时,无法检出到其他分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图结帐到另一个分支



我有一个.gitignore文件,其中包含

  .someFile 

尝试结帐到另一个分支时,即使我没有任何更改

  dev @ cool:〜/ proj / source $ git status 
#分支主
无提交,工作目录干净
dev @ cool:〜/ proj / source $ git checkout someBranchName
错误:您对本地文件的更改将被checkout覆盖:
.someFile
请在您切换分支之前提交您的更改或存储它们。
正在取消
dev @ cool:〜/ proj / source

文件从.gitignore并再次添加它没有帮助

运行命令:

  git update-index --assume-unchanged .someFile 

  git rm --cached .someFile 

没有帮助

有什么想法?

解决方案

在这种情况下,git尝试应用的区别在于添加新文件.somefile,但仅限于在应用程序中添加新文件.somefile



然后它会发生冲突。



如果您想要用目标分支的版本覆盖文件,然后你可以在切换之前在工作树中简单地删除它。



如果你想保留被忽略的文件,那么你可以重命名为put放在一边(这不会导致任何冲突,直到它的新临时名称与其他文件名称不匹配)。然后做一个开关。之后,只需将.somefile替换为临时重命名的文件。

如果内容不匹配,会导致工作树更改为文件。


Trying to checkout to another branch

I have a .gitignore file with

.someFile

trying to checkout to another branch fails even when i dont have any changes

dev@cool:~/proj/source$ git status
# On branch master
nothing to commit, working directory clean
dev@cool:~/proj/source$ git checkout someBranchName 
error: Your local changes to the following files would be overwritten by checkout:
    .someFile
Please, commit your changes or stash them before you can switch branches.
Aborting
dev@cool:~/proj/source$ 

removing the file from .gitignore and add it again didnt help

running command :

      git update-index --assume-unchanged .someFile

or

 git rm --cached .someFile

didnt help

any idea ?

解决方案

Switching between branches should be treated as applying patch that represents the difference between them.

In your case the difference that git tries to apply is "add new file .somefile, but only in case that it doesn't exist.".

Then it runs into conflict.

If you want to overwrite file with the version from target branch then you can simply delete it in work tree before switch.

If you want to preserve ignored file then you can just rename it to put aside (this would not cause any conflict until its new temporary name doesn't match with some other file name). Then make a switch. After that just replace ".somefile" with the one that you temporary renamed.
This would cause work tree change to file if content will not match.

这篇关于GIT - 当没有提交 - 当文件处于gitignore时,无法检出到其他分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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