I am at branch feature/branch1
, git status
list me two files that are on the .gitignore
file. When I try to checkout to develop
branch, git prevent me with this message:
error: Your local changes to the following files would be overwritten by checkout:
XXXXXXX.xcworkspace/xcuserdata/XXXX.xcuserdatad/UserInterfaceState.xcuserstate
Please, commit your changes or stash them before you can switch branches.
Aborting
Then I try to add these files although they are listed in the .gitignore
file, so I got this message:
The following paths are ignored by one of your .gitignore files:
XXXXXXX.xcworkspace
Use -f if you really want to add them.
fatal: no files added
Why git asked me to add these files? is it because they are not ignored in the develop
branch. And what best option to deal with such situation? Thanx in advance.
The problem is that you have the files in your local directory, although they are not versioned by git. And git checkout is trying to pull in these files which are versioned. Git is telling you that it's attempting to overwrite the files, but they are not versioned, so you have 2 choices:
git add -f <ignored files>
) To see all of the ignored files in your repo directory, run:
git status --ignored
This will list all your Ignored files, from here you can decide if you want to move, remove or version them before running git checkout <branch>
.
After you checkout this branch, you might also want to consider that the ignored files coming in from the branch you're trying to checkout really should not be committed to the git repo, you can remove the files from the repo without deleting them:
git rm --cached <files>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.