

In the above example, git push origin new-branch-demoįound this post helpful? Then check out further posts on. Now, publish this branch to GitHub using git push origin 30. the GUI application - NOT command line) to go back to a previous commit (on the same branch). In order to create a new branch from a specific commit, you can run the following command: git branch įor instance, in the above case, you could run the command: git branch new-branch-demo 360421f Going back to a previous commit in Github Desktop Ask Question Asked 7 years, 5 months ago Modified 8 months ago Viewed 138k times 84 I am trying to use GitHub Desktop (i.e. This way, no data will be lost, and the old branch can soon be pushed into insignificance.
#GITHUB REVERT TO PREVIOUS COMMIT CODE#
If you need to include code changes to your last commit, you can do that in the Git Changes window. When you finish editing your commit message, select Amend. Instead of deleting history from GitHub, what you can do instead is create a new branch from the specific commit of your interest, and start development on this new branch. Open the commit details of the last commit by double-clicking it, and then select the Edit option next to the commit message. All commits AFTER 360421f (or whatever commit ID you selected) have been deleted. git push -f origin įor instance, if you are on the master branch, git push -f origin master Step 3: Finally, force push this to the origin branch. This StackOverflow answer does an excellent job of explaining it. You may be wondering the significance of the –hard qualifier.

Go to the folder/directory of the project of your interest, make sure you are on the correct branch (using git checkout ), and then run git log (press q to quit the logs) Step 2: Run the following command in the command line: git reset -hard Git - Revert the previous commits using GitHub. Step 1: Get the commit ID of the commit you wish to take your branch back to Tip: When you revert multiple commits, it's best to revert in order from newest to oldest. The original commit also remains in the repository's history. When you revert to a previous commit, the revert is also a commit. You will be essentially tampering with history, and making irreversible changes by following the steps below. You can use GitHub Desktop to revert a specific commit to remove its changes from your branch. This should be avoided unless absolutely necessary. Please note that this is a very dangerous maneuver, especially when working with multiple collaborators.
