Can I go back once I have merged a branch to the master on Github?
I have gone through great difficulties with my first commit to the main project. Mainly because I did all the changes onto a downloaded code and not the cloned from master code. So eventually what worked for me was creating a local branch from the masters remote branch and then copy paste the changed code.
But that resulted in a rather messed up view once I try to compare the two. Since it shows everything as deleted and added.
So my question is: Once I merge my branch with the master at Github and for some reason it doesnt work out well, is there a way to go back to master prior my merge (without big difficulties)
Thank for all answers. Got it figured out thanks to the suggestions and first batch went live :)
Given that the merge commit is already live in master
, the safest bet here would be to revert that merge commit:
git checkout master
git revert -m 1 <commit hash of merge commit>
To find the commit hash for the merge commit in master
, just type git log
from the bash and find the commit.
This approach makes a new commit on top of master
which functionally undoes the merge commit. You may push your master
branch as usual. If going through a pull request to master
, there also should be no hang ups with this approach.
Note: The -m 1
option used above in git revert
tells Git to use the first parent, ie master
as the track to follow. We could also have used -m 2
, which would follow the feature branch which is the source of the merge.
For going back once committing the changes, you can use the command:
$git revert <commit hash code>
You can see the see the commit hash code by using the command:
$git log --oneline
This will show the commit hash code and the commit message.
By using the revert command only the lastest commit can be reverted.
After using the revert command in the git bash, if there is a conflict then you can abort the revert(in case you don't want to revert after seeing the conflict) by using the command:
$git revert --abort
After resolving the conflict if you want to continue, then use the command:
$git revert --continue
This process will revert the latest commit.
链接地址: http://www.djcxy.com/p/49800.html