Reputation: 3132
I am trying to make a Git pull request from the remote repository to local, but it shows below the error, and I am not able to pull.
For example, git pull origin master
:
error: The following untracked working tree files would be overwritten by merge:
db/development.sqlite3
db/test.sqlite3
log/development.log
log/test.log
tmp/cache/assets/C7D/310/sprockets%2F38d8bc4c0599099a0404900b377c353b
tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953
tmp/cache/assets/CDC/870/sprockets%2Fa77b26f54f3481a4b4daf08514b49074
tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016
tmp/cache/assets/D09/A10/sprockets%2Fd608b39f93a782efe7398ab3797f6948
tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705
tmp/cache/assets/D33/290/sprockets%2F94f084e7801a02e1fd62140be0f5e7cb
tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655
tmp/cache/assets/D57/600/sprockets%2Fec4b1ce010bcc065da023308f49a9d55
tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6
tmp/cache/assets/D6A/C30/sprockets%2Fd5b294a2f636c6ee22c18e24b19fdc41
tmp/cache/assets/D84/A20/sprockets%2Fd88ae988de6a691a6d472eee0441ad88
tmp/cache/assets/DCE/C90/sprockets%2Febaf322f09c9ee13f29fc061542fe6af
tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994
tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6
tmp/pids/server.pid
Please move or remove them before you can merge.
I just started using Git now and had no clue why this error happened. How do I resolve it?
Upvotes: 3
Views: 26969
Reputation: 14599
It means that:
master
of the remote repository.A quick-and-dirty solution if you want to merge: remove those local files:
rm -rf db log tmp
git pull origin master
Less quick, but cleaner solution: you're probably right: you shouldn't version binary or temporary files. A developer likely messed up when he/she added those files. You could ask him/her to fix it and pull
afterwards.
You could also fix it yourself, that is: after having pulled, you could do
git rm -rf db log tmp
git commit -m "Removed binary and temporary files from Git"
To ensure sure an error will not happen again, after removing them, you could ask Git to ignore those files, to ensure they won't be added again by mistake.
To do it, add a file called .gitignore
at the root of your repository, and make it like this:
*.sqlite3
*.log
tmp
BTW, after adding this file, you could try doing a git status
, to see that Git doesn't care about them any more.
Upvotes: 1
Reputation: 124648
You have untracked files in your working tree. Those listed in your post. Some of the commits you're trying to merge with git pull
would be overwritten by the merge. This is not safe. It cannot be safe, because these files are untracked, so Git cannot possibly know what to do with them. Should it keep the files you have and ignore the incoming changes? Should it overwrite them? It cannot possibly know, only you can know. So it refuses to do something dangerous.
Normally, you need to move these files out of the way. For example, create a temporary directory and move these files there. Or put them in a backup file and delete the files from the working tree.
I wrote normally, because this looks like a special case. Your local repository is correct that these files are not tracked: tmp/*
look like temporary cache files, log/*
files look like log files, and db/*
look like binary database files. None of these should be tracked by version control, normally. But they are tracked now in the remote repository you are trying to merge from. It looks like a developer made a mistake and added these files to version control by accident.
The best thing to do is to find the developer who aded those files and ask him to clean up after himself (so he doesn't do it again). After he removes the files from the repository and pushes again, your git pull
command will work.
If it's difficult to get the author to fix the problem in the repository, you can fix it yourself:
# create a clean clone to preserve your workspace
git clone URL /tmp/cleanup
cd /tmp/cleanup
# remove the junk
git rm -r db log tmp
# commit the fix (copy-pasted from @gturri's answer)
git commit -m "Removed binary and temporary files from Git"
git push
After this your git pull
command will work.
Finally, something that should help preventing mistakes like this is correctly configured .gitignore
files in the project. In your current workspace, if you do git status
and you see tmp
, log
, db
as untracked, that's not so good. That means these directories are not marked to be ignored and it's easier to make mistakes like this and accidentally commit these files. In that case, update your .gitignore
, that will make it a lot harder to make a mistake like this in the future.
Upvotes: 0