开发者

Git warning of file overwriting due to (supposedly) untracked files

开发者 https://www.devze.com 2023-04-10 08:53 出处:网络
Attempting to pull from git repo, but getting the following output. I think these files are tracked (As they should be), but its indicating that they are not. They are not in .gitignore. I am about 5-

Attempting to pull from git repo, but getting the following output. I think these files are tracked (As they should be), but its indicating that they are not. They are not in .gitignore. I am about 5-10 commits behind the branch.

git pull --rebase origin master
From github.com:user/Project
 * branch            master     -> FETCH_HEAD
First, rewinding head to replay your work on top of 开发者_如何学编程it...
error: The following untracked working tree files would be overwritten by checkout:
mountdoom/protected/models/UserHelper.php
mountdoom/protected/models/UserRegistrationForm.php
mountdoom/protected/runtime/state.bin
mountdoom/protected/views/site/register.php
Please move or remove them before you can switch branches.
Aborting
could not detach HEAD

Any ideas how to resolve this?


They're tracked in the version you're checking out, but not in the version you had checked out previously. If you don't care about the untracked versions, just remove them.

If you do care about them, commit them before doing the rebase. You may then have to merge as part of the rebase process.


You can add the untracked files to the index (git add), git stash them, then do your git pull --rebase and then git stash pop and resolve conflicts if any.


If you simply want to delete the files like I do, you can run

rm `git merge 2>&1 | sed "s/^[^\t].*/ /g" `

(you might want to run it first with echo instead of rm to verify the results)


So it seems a scenario for this problem is when a file has been deleted and you still have a copy of it. For some reason, git fails to understand it.

None of these suggestions worked for me.

Finally I could fix it by git rm filename, git commit -m "temporary commit", then git pull --rebase.

At this point, git complained again and then I had to add the file to be tracked by git add filename, git commit -m "temporary commit2", then git pull --rebase.

Then everything went well. And I do not see my temporary commits as they cancel out each other.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号