标签云

微信群

扫码加入我们

WeChat QR Code

以下跟踪工作树文件会检测被覆盖

So I added a folder to my .gitignore file.

Once I do a git status it tells me

# On branch latest
nothing to commit (working directory clean)

However, when I try to change branches I get the following:

My-MacBook-Pro:webapp marcamillion$ git checkout develop
error: The following untracked working tree files would be overwritten by checkout:
    public/system/images/9/thumb/red-stripe.jpg
    public/system/images/9/original/red-stripe.jpg
    public/system/images/8/thumb/red-stripe-red.jpg
    public/system/images/8/original/red-stripe-red.jpg
    public/system/images/8/original/00-louis_c.k.-chewed_up-cover-2008.jpg
    public/system/images/7/thumb/red-stripe-dark.jpg
    public/system/images/7/original/red-stripe-dark.jpg
    public/system/images/7/original/DSC07833.JPG
    public/system/images/6/thumb/red-stripe-bw.jpg
    public/system/images/6/original/website-logo.png
    public/system/images/6/original/red-stripe-bw.jpg
    public/system/images/5/thumb/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/5/original/logocompv-colored-squares-100px.png
    public/system/images/5/original/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/4/thumb/DSC_0001.JPG
    public/system/images/4/original/logo.png
    public/system/images/4/original/DSC_0001.JPG
    public/system/images/4/original/2-up.jpg
    public/system/images/3/thumb/logo2.gif
    public/system/images/3/original/logo2.gif
    public/system/images/3/original/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/3/original/11002000962.jpg
    public/system/images/2/thumb/Profile Pic.jpg
    public/system/images/2/original/Profile Pic.jpg
    public/system/images/2/original/02 Login Screen.jpg
    public/system/images/1/original/Argentina-2010-World-Cup.jpg
Please move or remove them before you can switch branches.
Aborting

This is what my .gitignore file looks like:

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/**/*
public/system/images/*
public/system/avatars/*

How do I get this working so I can switch branches without deleting those files?

If I make a change, will it affect those files? In other words, if I came back to this branch afterwards would everything be perfect as up to my latest commit?

I don't want to lose those files, I just don't want them tracked.


Thanks....I removed all the files from the current branch and backed them up. Then switched branches and put them back. That worked. Also, thanks for the tip on the .gitignore though

2018年05月27日26分42秒

marcamillion: What do you mean by "that worked"? If the files were tracked on the branch you switched to, you've overwritten them with your versions, which could be different...

2018年05月27日26分42秒

I was having an issue with a /build folder that doesn't need to be tracked. So I deleted the local folder, committed my .gitignore file, then checked out the other branch. That finally worked for me.

2018年05月27日26分42秒

I think the first part is for the reverse of this particular error message. This error is stating the user is currently in a branch that doesn't have those JPG files tracked and the user is trying to move to one that does. So doing git rm --cached will not make a difference, those files don't exist in the current branch. For this error I think the user instead needs to follow Greg Hewgill's answer - "move them out of working copy, switch branches, and move them back".

2018年05月27日26分42秒

How would one go about solving the your files would be overwritten with fatal: pathspec 'test/node_modules' did not match any files when I do git rm -r --cache test/node_modules? I can't pull because of the overwritten message and can't remove because git can't find them (they are there)

2018年05月27日26分42秒

Thanks, after that clean I was able to rebase;

2018年05月27日26分42秒

BE CAREFUL WHEN RUNNING git clean!

2018年05月27日26分42秒

To avoid a facepalm, first run it with the dry-run option to see what it would do: git clean -dfxn or git clean -dfx --dry-run

2018年05月27日26分42秒

Holy crap. This deletes all the config files on my xcode and now the project is turning into mac project. BE VERY CAREFUL WHEN RUNNING THIS COMMAND. I thought it would only remove it from git.

2018年05月28日26分42秒

The -x option hurts me

2018年05月27日26分42秒

Easy and straight solution for me for the similar issue in question!! Thanks a ton Régis!!

2018年05月28日26分42秒

Warning: This will delete the local files that are not indexed.

2018年05月27日26分42秒

I didn't want the file that was not indexed! +1 for you

2018年05月27日26分42秒

this is the only one that worked out of all the others

2018年05月27日26分42秒

Time saving command for me

2018年05月27日26分42秒

It worked on Windows as well, looks like this situation happened in the first place due to case change which GIT couldn't determine

2018年05月28日26分42秒

This is exactly the problem I had, a file path was different by one letter case - Windows treats this as same but GIT does not which is the problem.

2018年05月27日26分42秒

My problem happened in checkout another branch in Windows 10, and only this work for me, Thanks

2018年05月27日26分42秒

awesome! this fix my problem when I was moving between tags

2018年05月27日26分42秒

awesome. thanks!

2018年05月27日26分42秒

Thanks for the explanation. I backed up the files, switched branches and merged them then replaced the files in the public folder. That worked.

2018年05月27日26分42秒

As I commented on Arrowmaster's answer. This is the right answer for the error message. It may not be the right answer for this particularly questioner since he real problems seems to be his gitignore.

2018年05月27日26分42秒

This helped me, when my issue was not related to .gitignore afaik.

2018年05月27日26分42秒

This answer is already posted above

2018年05月27日26分42秒

+1 I was able to use git log on the current branch and branch to rebase to see when the commit occurred that changed the case; then I hacked around it...

2018年05月27日26分42秒

wisbucky - Thanks! :)

2018年05月27日26分42秒

I also had the same issue as Won. I added a .gitignore to a folder that was already getting tracked. I deleted the file and then was able to do a git checkout.

2018年05月27日26分42秒

Please add explanation on your solution. see stackoverflow.com/help/how-to-answer

2018年05月27日26分42秒

How to get over this error in that case? This message also appears when switching branches after changing the case in a file name (MyFile => myfile).

2018年05月27日26分42秒