How can I remove my last commit in my local git repository

When I do a ‘git pull’, I have conflict with the head commit. So I did a ‘git rebase –abort’

Can I ‘save’ my commit to a “patch” and then do a git pull?

  • How can I save an incompletely merged index in git?
  • git: stage only new files
  • Git/Bash is extremely slow in Windows 7 x64
  • Add remote via JGit
  • What is the convention for committing ugly code to a git repository?
  • How to checkout particular pull request
  • What I want to emulate is:

    • I did not commit, but I did a ‘git stash’ instead
    • Do a git pull to avoid any merge error

    So I need somehow to ‘turn back the clock’. Is that possible with git?

  • git - squash before rebasing
  • Tracking a remotes/p4/master branch in git
  • Exclude commits from Git hooks?
  • Git: Commit an unresolved conflict
  • Git: how to make remote directory update when pushed to?
  • Are DVCS like Git inappropriate for teams using continuous integration?
  • 4 Solutions collect form web for “How can I remove my last commit in my local git repository”

    Your 7826b2 patch will still cause a conflict when it’s applied after pulling, but you can do the following:

    git reset --soft HEAD^
    git stash
    git pull
    git stash pop # Will cause a conflict
    git commit    # Re-commit 7826b2

    Another workflow is also possible:

    git reset --hard HEAD^
    git pull
    git cherry-pick 7826b2 # Will cause a conflict

    The second workflow relies on the fact that Git keeps the 7826b2 commit in the reflog (you can think of it as the recycle bin) even though you reset the changes it introduced with the first line.

    If you did commit your changes in your local repository, you could do a straight rebase:

    git fetch origin

    git rebase origin/master

    This unwinds your local commits from the local master, applies new commits from origin/master, and then replays your local commits.

    In your situation, this will result in a conflict and git will tell you which files need to be edited to resolve the conflict. After you do so, git add those files and then git commit with no arguments to recommit the changes.

    There is a way, in fact in git, I’m sure there’s a multitude of ways of doing it…

    You could do:

    git stash     # Stash your changes
    git pull      # Pull the changes
    git stash pop # Pop your stash

    You could do:

    git pull --rebase # Bring in the changes and apply yours on top of it.

    You could do:

    git stash     # Stash your changes
    git checkout <commit> # Pull a specific commit.
    git stash pop # Pop your stash

    Hope it helps.

    First I suggest to do a backup of your branch:

    git branch your_branch_backup

    Then the easiest way is:

    git reset --soft <commit> #Go back in time but without loosing your changes
    git stash                 #Stash your changes
    git pull                  #Refresh your branch with origin
    git stash pop             #Re-apply your changes on the refreshed branch 

    Then you can commit as usual

    Git Baby is a git and github fan, let's start git clone.