Here I am discussing how to revert a merged pull request and again push the branch. I am sharing this because I faced this issue while developing something...
Keep in mind that the working branch is "master" and the feature branch is "navbar".
If you don't know how to push your code into github, please visit my previous post here
Here we go...
The problem 1: I created a pull request in github and merged. But that isn't the actual code, or it's not working in the master branch after merging.
The merged file was navbar.
The solution: Let's checkout branch into master and pull the code from github, then check git log.
git checkout master
git pull origin master
git log
You can see a commit message like "merge pull request."
You can revert the commit using that commitId and a git command like
git revert -m 1 714013e1e7dc98787b73b9da197994b770d0c1d7
You can write the commit message for reason for reverting in the opening window and press ctrl x
. Then push the code into github.
git push origin master
Now you reverted your pull request successfully. You can see that your merged files are removed now and a new commit message. Eg: here navbar file removed.
The problem 2: What What happens if you want to work in the navbar branch and create a new pull request again?
The solution: checkout into the branch navbar and work in the navbar branch and create a pull request.
git checkout navbar
After editing the file, add, commit and push.
git add .
git commit -m "navbar edited"
git push origin navbar
Go to GitHub and select the navbar branch.
You can see a contribute button; by pressing that, you can create a new pull request.
If there aren't any conflicts, it can merge. If there are any conflicts, first of all, go to your IDE checkout to the master branch and pull the code from github. Then checkout to branch navbar, then merge master into navbar.
git chekcout master
git pull origin master
git checkout navbar
git merge master
Now you can see the conflicts and solve the conflicts in the merge editor (hoping you are using vs code), select the incoming code.
Complete the merge, add, commit, and create a pull request once again.
Now you can create a pull request for the navbar branch by selecting the navbar branch, then clicking the contribute button and opening the pull request, create pull request.
You can see that conflicts are solved.
Thankyou
Happy coding:)
Author Of article : Arun Krish Read full article