2017-07-09 10 views
4

私はmasterブランチを持っています。このブランチはPRだけのプッシュで保護されています。コミットを元に戻す方法、新しいブランチを作成してPRを行う方法は?

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

しかし、私はブランチにプッシュし、枝が保護されているために拒否されています:

は私が軽率masterに言います。 バックトラックを取り、変更を保存してPRするにはどうしたらいいですか?

+0

'origin/master'からプルして、最新のコミットにリベースしてください。 –

+0

[Gitを使って最新のコミットを新しいブランチに移動](https://stackoverflow.com/questions/1628563/move-themost-recent-commits-to-a-new-branch) -with-git) – Clint

答えて

5
  1. を押しますmasterブランチのコミットの最後を元に戻します。

    $ git reset --soft HEAD~1  # undo the last commit and keep the changes in working tree 
    
  2. 新しいブランチにチェックアウト(たとえば、feature)、その後、追加コミットとリモート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 

featureブランチからPRを作成します。


代替:

  1. 新しいブランチにチェックアウト(たとえば、feature)とリモートにfeatureブランチをプッシュします。

    masterブランチへ
    $ git checkout -b feature 
    $ git push origin HEAD 
    
  2. 切り替えて、最後のコミットを元に戻します。今

$ 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を作成します。

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

リセットHEAD〜は最後のコミットを元に戻します。チェックアウト-bは、新しいブランチをチェックアウト作成し、その後、あなただけの追加とコミットして変更をそこに

関連する問題