Reputation:
I have some local changes and I know the repo has moved ahead since my last pull. When I do git pull, i get below message -
$ git pull
Enter passphrase for key '/c/Users/xxx/.ssh/id_rsa':
remote: Counting objects: 65, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 65 (delta 29), reused 0 (delta 0)
Unpacking objects: 100% (65/65), 16.35 KiB | 7.00 KiB/s, done.
From bitbucket.org:abc/someproject
ashljkl..db9e852 feature/somefeature -> origin/feature/somefeature
error: Your local changes to the following files would be overwritten by merge:
src/main/java/com/somefilepath
Please commit your changes or stash them before you merge.
Aborting
Updating ashljkl..db9e852
From this SOF post: How do I ignore an error on 'git pull' about my local changes would be overwritten by merge? I could figure out how to resolve this issue. 1) git stash local change 2) git pull 3) then git stash pop the stashed changes.
But I want to know if there is an further easier way of handling this - just say to git pull
with some options/flags to merge the changes from repo with my local changes directly. In the process of merging, if there are conflicts, i am fine with git showing conflicts and placing conflict markers in the source files that have conflicts.
Upvotes: 1
Views: 130
Reputation: 76409
There is no simple easy way to do this. The simplest, best way to go about this is to stash your changes, and then pull.
The reason this is the case is that any sort of merge that happens here involves the index. The merge would write changes into the index and then check out the files. Your changes may or may not be in the index. If you have not run git add
on that particular version, it will not be in the index, and any merge operation would destroy it during the checkout rather than actually performing a merge.
If those changes are in the index, you could try to do a git fetch
and then perform a merge yourself with git read-tree -um
, checking out the files. However, in this case, the three-way merge that Git does isn't the same as a normal recursive merge, so you lose any ability to have things like renames work. As such, while this is possible, it's not a good choice, and you will likely be unhappy with the results. You'd also have to do the merge base calculation yourself (or script it), which is a bunch of hassle.
So the best solution is to stash here.
Upvotes: 1