Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
國家政權建設,並承諾在我的本地主分支的一些變化之後。
如何將本地更改分揀到新分支?
我希望得到的結果是:本地/主機與源/主同步,並且我有一個本地分支,其中有兩個提交。
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
國家政權建設,並承諾在我的本地主分支的一些變化之後。
如何將本地更改分揀到新分支?
我希望得到的結果是:本地/主機與源/主同步,並且我有一個本地分支,其中有兩個提交。
首先
git checkout -b newBranchName
這將創建一個新的分支,同樣爲您正在使用的當前主。
之後,
git checkout master
這將選擇主作爲當前分支。
最後
git reset --hard origin/master
這將從主刪除那些2次的提交,但他們將仍然提供newBranchName
編輯:作爲@ShmulikKlein提到,要小心--hard
..你可以隨時使用--soft
然後放棄更改
@Matias是對的,但首先,在使用git reset --hard
時應該非常小心,同時回顧最後2次提交,也將消滅你完全工作的目錄和暫存區域(又名未分類和未被更改的更改)。第二,我認爲當您在master
分支上時,最後一步應該是git reset --hard HEAD~2
,因爲您只想恢復最後2次提交,因爲您不知道自發布問題後origin/master
是如何更改的...(除非使用git status
進行檢查...)
可能的[使用當前更改創建Git分支]的副本(http://stackoverflow.com/questions/3899627/create-git-branch-with-current-變化) –