分支提交的文件不见了_GIT - 当没有提交 - 当文件处于gitignore时,无法检出到其他分支...

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值