4

I had worked with Mercurial but now working with Git. I have some difficulty with understanding Git, can you help me, what are the alternatives to Git commands like Mercurial:

hg up -C 
hg revert --all 
hg purge

If I have some conflicts from the Mercurial command "hg up", I can run commands like hg revert --all & hg purge or hg up -C.

What can I do after git pull and file conflicts if I don't want to continue, but just revert to the original state, or update files without conflicts (like hg up -C)?

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360

2 Answers2

5

You can refer to Git hg rosetta stone

For example:

hg update -C    git checkout -f 
hg revert -a    git reset --hard 
hg purge        git clean -fd 

So see:

Also:

And finally: "Undo git pull, how to bring repos to old state"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for answer. I tried to follow your advice. After command `git reset --hard` all changes are discarded, then I run command `git checkout -f` and got next message http://screencloud.net/v/x2p5 Then I check file changes and new changes are not applied. After then I run command `git status` and got message http://screencloud.net/v/8Dl9/. then I run command `git pull` again, I got conflicts again =(((( It is confuse, because if I have clean working directory I can run command `hg pull` without conflicts, But if I run `git pull` I got conflicts – Антон Хороший Oct 21 '15 at 08:17
  • For your `git checkout -f` error message, see http://stackoverflow.com/a/2452610/6309 – VonC Oct 21 '15 at 10:39
0

What can I do after "git pull" and file's conflicts, if I don't want to continue, but just revert to the original state

When you do a git pull, you are really doing a git fetch followed by either a git merge or a git rebase. Assuming your pull strategy is using merge, then your question is how can you undo the merge done during a git pull. One clean way to undo a merge is to reset your local branch to the latest commit:

git reset --hard <SHA-1 hash of latest commit>

What can I do ... update files without conflicts (like hg up -C)

When you do a git pull, you bring in the changes to all the files from the remote branch. Usually you would not want to update only files which have no conflicts. Git is a workspace-based version control system, as opposed to something like SVN, which is a file-based VCS.

If you really want to try doing a git pull and then update only files which are not in conflict, then you can use the following command to identify which files have conflicts:

git diff --name-only --diff-filter=U

Then for each file in the list, you can do a git reset on it:

git checkout -- filename_in_conflict
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • Were you looking for a way to map Mercurial commands, or info on how to actually execute in Git? – Tim Biegeleisen Oct 21 '15 at 07:59
  • I don't understand Git =( If I run `hg pull & hg up -C` I always get the actual code in working directory without conflicts, But `git fetch & git checkout -f` is not `hg pull & hg up -C`. If I run command `git checkout -- filename_in_conflict` I got message http://screencloud.net/v/scPD – Антон Хороший Oct 21 '15 at 09:08
  • My advice is to you is to post a new question where you specify _exactly_ what you are trying to do in Git. You will get an answer that can get you started. – Tim Biegeleisen Oct 21 '15 at 09:09
  • thank you very much for your help. here is my new question http://stackoverflow.com/questions/33255900/git-how-to-update-the-working-directory-like-hg-up-c-in-mercurial – Антон Хороший Oct 21 '15 at 09:46