Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 47
    I'm just asking for a, uh, friend - how would you go about undoing the first code block you have here (checkout/fetch/merge)? Commented Sep 17, 2014 at 9:13
  • 11
    @RichBradshaw: git checkout is normally non-destructive and there's normally no reason to undo a git fetch, so it sounds like you're asking how to back out a merge commit. The answer is the same as for other commits: either git reset or git revert. For unpublished changes git reset is usually the best method; for changes others already have, git revert may be better, but see Linus Torvald's advice on reverting a merge: kernel.org/pub/software/scm/git/docs/howto/… Commented Sep 17, 2014 at 16:15
  • 2
    @WeDoTDD: I don't understand the question. There are a number of commands for viewing the commit graph (gitk, git log --graph with or without --oneline, and so on) and you can git show or git show -m a merge commit, or use git diff. In all of these cases, you're specifying the program as you enter the command on the command-line. Commented Aug 10, 2015 at 20:02
  • 1
    @torek: tried your way of: git checkout branch and then git pull origin master, but it pulled all master changes as a single change which should be committed locally again, instead of pulling them with their commit history and messages, so after updating local master and switching to branch, "git rebase master" does the job with all conflicts to solve, and then I add to "git pull --rebase" and handle again all conflicts, and then git push origin branch to get all aligned. I guess there should be better way for it - am I right? Commented Feb 13, 2019 at 10:20
  • 3
    For those who are wondering why this git pull origin master does not work, Github has renamed the master branch to main. So you should try git pull origin main. Commented Apr 27, 2022 at 4:56