0

I have a strange problem where a git pull is not completely updating a certain file.

I am working on a company project which has just one remote. My local repo is 3 commits ahead of the remote and in the meantime some other commits were pushed by another developer. We are both working off master.

So my scenario is, I stashed my local changes, pulled down the latest changes and noticed a conflict. No problem.

I resolved that conflict but then discovered that the resolution results in broken code. I checked the source code on the remote through Bitbucket and noticed that one of the methods in my code has not been updated at all. Please see below as an example.

Local repo (before pull)

public Object method1() throws Exception {
    return method2();
}

public Object method2() throws Exception {
    return generateSomeObject();
}

Remote repo (first method is renamed and different exception thrown)

public Object newMethod1() throws SQLException {
    return method2();
}

public Object method2() throws SQLException {
    Object object = null;
    try {
        object = generateSomeObject();
    catch (SomeException e) {}
    return object;
}

This results in a conflict like so After pull

<<<<<<< HEAD
public Object method1() throws Exception {
======
public Object newMethod1() throws SQLException {
>>>>>>> 453451432435
    return method2();
}

public Object method2() throws Exception {
    return generateSomeObject();
}

The conflict makes senses so that's fine. However, I don't understand why method2 hasn't been updated correctly. I would have expected it to show a conflict as well. As such all changes to this method have not been pulled down from the remote.

Can anyone shed any light on fixing this within git rather than copying across the omission manually?

Matt R
  • 1,276
  • 16
  • 29
  • 1
    `I stashed my local changes, pulled down the latest changes and noticed a conflict. No problem.` ... actually this _is_ a problem, if you really got the conflict just from pulling. Stashing your work should have put your local branch into a position where it can be simply fast-forwarded by the remote branch. If you didn't apply the stash and really got a conflict, then someone may have messed with the history of this branch. – Tim Biegeleisen Feb 03 '17 at 01:43
  • Thanks @TimBiegeleisen. The conflict is due to diverging history between my local commits and the remotes. I didn't find that unusual but the fact method2 wasn't updated was strange. However, your comment prompted me to look back over my own local history to ensure that the difference isn't a result of my changes. In fact it was. No conflict was shown because it appears I had already made that adjustment in my unpushed history. So, my error. Thanks for prompting me to look here – Matt R Feb 03 '17 at 02:43

1 Answers1

1

It seems merge is interrupted by occurred conflict. After you solved conflict, you can run git pull once more to resume your merge. git merge --continue is also available in newer git version.

For more information about resume git merge, you can read how-do-i-finish-the-merge-after-resolving-my-merge-conflicts

Community
  • 1
  • 1
gzh
  • 3,507
  • 2
  • 19
  • 23
  • 1
    Thanks @gzh, this is useful to know going forward. The issue appears to have been because I had already resolved this potential conflict in one of my unpushed commits already. I had just missed it which is why I couldn't explain the anomaly. I wasn't even aware that git could be interrupted by a conflict so thanks for that nugget of info – Matt R Feb 03 '17 at 02:45