tubelobi.blogg.se

Git undo commit before push
Git undo commit before push













Merge pull request #1 from Akshay/revert-test Note that the merge commit - 2ec06d9 has two parents now - 12a7327 (in main) and 15bde47 (in revert-test), checking git log now, > git logĬommit 2ec06d9d315a3f7919ffe4ad2c2d7cec8c8f9aa3 (HEAD -> main, origin/main, origin/HEAD) I want to undo the merge commit and go back to the last commit in the main branch - which is 12a7327 Then, created a pull request from GitHub and merged revert-test branch to main. Now, I've added some new files, modified existing files, and created separate commits on each branch, then pushed them to the origin.

#GIT UNDO COMMIT BEFORE PUSH CODE#

(For graphical view of commits use -graph with git log OR this more interactive VS code extension - git graph)

git undo commit before push

# remember to check and verify the parent1 and parent2 with git log command.Ĭreated a new branch revert-test on an existing project that has only main branch, The commit graph looks like this now.

git undo commit before push

# To revert to C4 in master branchįor some other cases, if needed revert to C5, # revert to C5 in iss53 branch Switch to the branch on which the merge was made ( it is the master branch here and we aim to remove the iss53 branch from it )ĭo the git revert with -m 1 flag. The C4 commit is in master branch and we need to revert to that, that is parent 1 and -m 1 is needed here (use git log C4 to verify the previous commits to confirm parent branch). It will be in the format of Merge: parent1 parent2, here Merge: C4 C5. So it must specify which parent to use for the revert command.įor that check the git log, ( here representing actual commit hash with code names from graph) > git logįrom git log output, note down the parent IDs that come with Merge:. Need to revert C6 and return the repository to its state at C4. The iss53 branch was merged into master, creating a Merge Commit, C6. As git cannot determine which parent is the mainline and which is the branch to un-merge automatically, so this must be specified.

git undo commit before push

To specify the desired parent, uses the -m flag. Reverting a merge commit is not straightforward as with git revert, since Git gets confused when looking back from the merge commit due to its two parent commits. More explanation for given answer git revert -m 1 with a graphical representation and an example, step-by-step.













Git undo commit before push