Git: Branch is ahead by X commits. Doesn't help doing git pull

后端 未结 4 1637
无人及你
无人及你 2021-01-03 03:16

I do see other similar questions, but I dont really understand why this happens. For now, I am using git reset --hard HEAD then manually adding back my changes.

4条回答
  •  孤城傲影
    2021-01-03 03:48

    I investigated same issue in my env and found these facts:

    Origin/master is mark(label) on commit where I performed clone. I didn't create any commits on my side, just pulling without rebase from origin. This caused syncing my side of repo but didn't move or update origin/master position. Same situation appears if you perform push (origin/master label moves to your push position) and then do some pulls which fetch some new commits.

    git log --graph --oneline -X master
    

    where X is number >= number of commits "ahead" you can see after git status call. You can see in log result where is positioned origin/master mark. This internal git mark is used for calculating status message we are afraid of.

    Hash of the commit is stored in refs/remotes/origin/master file. If you delete this file the origin/master mark disappear and also information about ahead commits will no longer be displayed.

    If you want to sync origin/master mark to current master HEAD just type

    git update-ref refs/remotes/origin/master cac0cab538b970a37ea1e769cbbde608743bc96d
    

    where instead of my hash put your hash of the head from:

    git log -1
    

    or use copy/paste on file content if you wish. The result should be the same.

    This helped me with the message, but I don't know what else was also affected. As far as I know this message has just informative meaning and its not an error or warning. Everything works for me as expected without any limitation.

提交回复
热议问题