git: Your branch and 'origin/somebranch' have diverged - how to throw away local commits
Asked Answered
C

3

28

I have a question that most closely matches my problem was made, but could not add a comment.

git: Your branch and 'origin/master' have diverged - how to throw away local commits?

I ran the tips and answers to the question above, but nothing decided. I am following with a progress chart using the sofwae source tree. I close the software and run the commands in the bash git. But there is the same mistake quoted.

# Your branch and 'origin/master' have diverged,
# and have 7 and 11 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)

I am also facing the same problem. follow the steps running 2 comentos but not worked. I think my problem is that before I made a checkout for a indiividual head, made a commit in individual head and then I went back to the tree branch / master, and commit that I did, I believe that references the tree head individual. In summary I can not undo this commit, I'm displayed graphically on SourceTree software

EDIT - ADD INFORMATION: I'd like to throw out of the unpublished commits and make server checkout. But the solutions I found an internet not working. I also tried git reverse in gitBash the console displays the message that I do deveo

$ Git status
On branch processos_criminais_151029
Your branch and 'origin / processos_criminais_151029' have diverged,
and 7 and 11 have different commits each, respectivamente.
   (use "git pull" to merge the remote branch into yours)

Changes not staged for commit:
   (use "git add <file> ..." to update what will be committed)
   (use "git checkout - <file> ..." to discard changes in working directory)

I tried the two solutions but none worked. If I try and push gives the conflict a huge amount of files, and I tried to solve these problems with the automatic merge, but to make a new git status he points out that the same quantidde files are conflicts.

Cumulonimbus answered 17/9, 2015 at 12:32 Comment(4)
“but not worked” – How did they not work, does the output from git status remain the same after running git reset --hard origin/master?Taite
What is it you're trying to do exactly. What do you expect the final state of the repo to be?Chor
I'd like to throw out of the unpublished commits and make server checkout. But the solutions I found an internet not working.Cumulonimbus
Possible duplicate of git: Your branch and 'origin/master' have diverged - how to throw away local commits?Slapdash
T
89

Your branch and 'origin / processos_criminais_151029' have diverged

So of course, resetting to origin/master will not work. You will have to reset to that remote branch in order to reset your local branch to it.

So the commands you need to run are this:

git fetch origin
git reset --hard origin/processos_criminais_151029
Taite answered 17/9, 2015 at 12:51 Comment(1)
Yes, this is what worked.Reste
P
-1

A local branch is considered "diverged" from a remote branch when the commit history of the local branch and the remote branch have diverged, meaning they have different commit histories.

There are several situations where your local branch can diverge from the remote branch in Git. one example would be: Suppose the commit history of the remote repo has changed very significantly in recent times as compared to the history of your local repo, this may due to someone in your team did hard reset to revert some unnecessary commits. Now as soon as you try to take a pull, you will get local branch and the remote branch have diverged.

If you have tried multiple solutions and none is working for you, A simple solution to this problem is to delete the branch locally and checkout once again, git will automatically create local copy which will be same as remote.

git branch -d <local branch>

If you are not able to delete because of merge conflict then use -D ~ alias of --delete --force

git branch -D <local branch>
Peduncle answered 4/1 at 7:54 Comment(0)
I
-5

I solved this problem with this link:https://mcmap.net/q/486915/-git-your-branch-and-39-origin-somebranch-39-have-diverged-how-to-throw-away-local-commits

But is important this steps for complete the answer Then I made a:

git pull

add changes to the files and do a:

git push

and everything works perfect

Regards

Incipit answered 26/6, 2017 at 6:46 Comment(1)
This creates a merge commitCommix

© 2022 - 2024 — McMap. All rights reserved.