我有一个被保护的master
分支,只能通过PR进行推送。
假设我在master
上不经思考地进行操作:
git add .
git commit -m "bunch of changes"
但是我推送到分支时被拒绝了,因为该分支受到保护。 我该如何回退、保留我的更改并发起一个PR(Pull Request)呢?
我有一个被保护的master
分支,只能通过PR进行推送。
假设我在master
上不经思考地进行操作:
git add .
git commit -m "bunch of changes"
但是我推送到分支时被拒绝了,因为该分支受到保护。 我该如何回退、保留我的更改并发起一个PR(Pull Request)呢?
Undo the last commit of master
branch.
$ git reset --soft HEAD~1 # undo the last commit and keep the changes in working tree
Checkout to new branch (say, feature
), then Add, Commit and Push to remote feature
branch.
$ 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
备选:
Checkout to new branch (say, feature
) and push the feature
branch to remote.
$ git checkout -b feature
$ git push origin HEAD
Switch to master
branch and undo the last commit.
$ 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
feature
分支创建PR(Pull Request)。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~会撤销您的最后一次提交。Checkout -b创建一个新分支并检出它,然后您只需在该分支上添加和提交更改,然后推送即可。
origin/master
拉取,然后在最新的提交上进行变基。 - Mateen Ulhaq