Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delete unpushed git commits?

Tags:

git

I accidentally committed to the wrong branch. How do I delete that commit?

like image 681
NullVoxPopuli Avatar asked Jul 07 '10 17:07

NullVoxPopuli


People also ask

How do I remove Unpushed commits?

Use the git reset Command to Remove Unpushed Commits in Git. Whenever we want to commit changes to the project directory, we can commit the changes using the git add and git commit commands. When using the git commit command, a commit is created in the local Git repository.

How do I remove a git commit?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

How do I delete Unpushed commits in Visual Studio?

Open the history tab in Team Explorer from the Branches tile (right-click your branch). Then in the history right-click the commit before the one you don't want to push, choose Reset. That will move the branch back to that commit and should get rid of the extra commit you made.

How do I remove a Unpushed commit in Sourcetree?

In the new window, select the commit you want gone, and press the "Delete"-button at the bottom, or right click the commit and click "Delete commit". Click "OK" (or "Cancel" if you want to abort).


1 Answers

Delete the most recent commit, keeping the work you've done:

git reset --soft HEAD~1 

Delete the most recent commit, destroying the work you've done:

git reset --hard HEAD~1 
like image 179
dbyrne Avatar answered Sep 27 '22 20:09

dbyrne