Git: "Updates were rejected because the end of your current branch is behind ..", but how do you see the differences?

I just finished work on a code snippet. I wanted to push and got the well-known:

hint

: Updates were rejected because the tip of the current branch is for a hint: its remote counterpart. Integration of remote changes (for example, a hint: 'git pull ...') before clicking again.

Now I have seen this question several times here, for example.

Updates were rejected because the hint of your current branch is behind the hint: its remote copy. Integration of remote changes (e.g.

Updates were rejected because the end of your current branch is behind

According to the specific case, the solution is either

  • git pull , so remote changes merge into my local work, OR
  • git push -f , push to update the remote (source) branch.

Now, I have not worked on this thread. I don’t necessarily want to integrate remote changes into my current work! I also don't know if I can safely force update the branch of origin ...

How can I just see the differences and decide which is best for my case?

+5
source share
2 answers

to see the differences, first you need to get commits from the source repository:

git fetch origin

Now you can see the differences (Assuming you are on the main branch) git diff HEAD..origin/master

Now you have the knowledge that you are trying to solve merge or rebase before push your changes.

+3
source

If you want to discard local changes , you must run git reset --hard @{u} . Please note that this is an irreversible action on some data, so it is mandatory before starting it. Here's how:

To find out what local commits you use, you can use git log HEAD --not --remotes to compare with any remote branch or git log @{u}..HEAD to see the differences specific to the tracked branch.

To see the actual diff that you made locally, run git diff @{u}... This ignores remote progress and only shows your changes.

To see uncommitted changes, run git diff HEAD .

PS: you must run git fetch origin or git remote update to update tracking links.

0
source

Source: https://habr.com/ru/post/1270179/


All Articles