How to undo a commit, put in a new branch, then do PR?

I have a branch masterthat is protected by pressing only PR.

Say I'm mindless on master:

git add .
git commit -m "bunch of changes"

But I click on the branch and deviate because the branch is protected. How can I step back, save my changes and do PR?

+4
source share
2 answers
  • Discard the last completion of a branch master.

    $ git reset --soft HEAD~1      # undo the last commit and keep the changes in working tree   
    
  • Make a purchase in a new branch (for example, feature), then add, commit and click on the remote branch feature.

    $ git checkout -b feature      # create and checkout to new 'feature' branch
    $ git add -A                   # add the changes 
    $ git commit -m 'message'      # commit 
    $ git push origin HEAD         # push to remote 'feature' branch
    

Now create a PR from the branch feature.


Alternative:

  • Place an order for a new branch (for example, feature) and direct the branch featureto the remote one.

    $ git checkout -b feature
    $ git push origin HEAD
    
  • master .

    $ git checkout master
    $ git reset --hard HEAD~1
    
    Or, (reset the local 'master' with 'origin/master')
    $ git checkout master 
    $ git fetch origin
    $ git reset --hard origin/master
    

PR feature.

+5
git reset HEAD~
git checkout -b "name-of-new-branch"
git -am "my fancy new commit"
git push origin "name-of-new-branch"

reset HEAD ~ . Check -b ,

+1

Source: https://habr.com/ru/post/1681048/


All Articles