2

I previously worked with the mercurial, but now with git. there were some problems, because git still a little different.

Could you suggest how you can update the git repository to the last commit, discarding all changes and conflicts, as it does for example hg up -C in Mercurial

I was advised to command git checkout -f, it displays this message:

Your branch and 'origin/master' have diverged, and have 24 and 5 different commit(s) each, respectively.

After applying this command, the files in the working directory are not updated.

Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263

2 Answers2

1

First, the error message you are getting is telling you that the local and remote versions of your branch have diverged. In order to get the changes from the remote branch you will either have to merge or rebase. Assuming you want to use a merge strategy, you can try this:

git fetch                             # get the latest changes from the remote
git checkout theBranch                # checkout your local branch
git merge -X theirs origin/theBranch  # merge with remote version of the branch

The -X theirs option in the git merge means that you will unconditionally keep the version of the files coming from the remote, overwriting whatever version you might have locally.

As this SO article discusses, if the merge results in a local file being deleted, then you may have to manually remove it using:

git rm /path/to/deleted/file

Then you can make your merge commit, and continue working.

Community
  • 1
  • 1
Tim Biegeleisen
  • 387,723
  • 20
  • 200
  • 263
  • Do I understand correctly that there were changes both locally and remotely, and there were two heads? – Антон Хороший Oct 21 '15 at 10:33
  • You are spot on. There is some common ancestor in the past, but the local and remote each have a unique set of commits on top of that common ancestor. So it needs to be resolved by doing a merge or a rebase (I suspect you want to merge in your case). – Tim Biegeleisen Oct 21 '15 at 10:34
0

The message you got is simply telling you that there is a different between the branch you've currently checked out and the local copy of its counterpart in the remote repository called origin. Then it proceeds to tell you that there are a number of commits local that are not remote and vice versa.

Simply pulling remote changes in and pushing remote changes out will remove this message. Git is very informative about a lot. This is nothing to worry about.

If git status does not show anything other right now you actually have discarded all changes that were not committed. One way is checking out a file, as you presumably did. This enable you to reset changes to a single or a couple of files. Another way is resetting your branch to head (simplified: the newest commit) using git reset HEAD --hard This obviously removes all changes in all files that were not committed.

Without the hard flag reset resets staged changes to unstaged changes. With the hard flag all changes are unchanged and undone.

hoppa
  • 2,981
  • 16
  • 21