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?

  • Manage python modules repeatedly updated in both local and original repository
  • Error with git commits: 'gpg-agent' is older than us (2.0.30 < 2.1.20)
  • Cannot trigger post-commit git hook on git submodule
  • What is the difference between 'git format-patch and 'git diff'?
  • Is there any harm letting a git branch “grow old”?
  • How can I restore a Git repo and its Github remote to a previous commit without using reset?
  • 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?

  • Customize gitk for each repository
  • git diff --numstat with --name-status
  • Rails “script/plugin” install…git hangs on 'git pull'
  • How to dynamically pick a git branch to use in Jenkins build
  • unable to remove file that really exists - fatal: pathspec … did not match any files
  • Removing non-repository files with git?
  • 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.