2017-09-19 37 views
1

我重置我的本地develop分支到後面的幾個提交,並且想推動本地develop分支到它的遠程,以便遠程的HEAD現在也重置爲少數提交後面。硬重置遠程分支到後面的幾個提交

換句話說,我不喜歡這樣:

UserName path/ (develop) 
$ git reset --hard {CommitIdOfAFewCommitsBehind} 
Your branch is behind 'origin/develop' by 14 commits, and can be fast-forwarded. 
    (use "git pull" to update your local branch) 
nothing to commit, working tree clean 


$ git push origin develop 
To https://github.devtools.merrillcorp.com/Javelin/wopi-poc.git 
! [rejected]  develop -> develop (non-fast-forward) 
error: failed to push some refs to 'https://github/repo.git' 
hint: Updates were rejected because the tip of your current branch is behind 
hint: its remote counterpart. Integrate the remote changes (e.g. 
hint: 'git pull ...') before pushing again. 
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 

如何使遙控器還去提交I​​D我想要的嗎?

回答

1

當您對develop分支進行了硬重置時,您重寫了該分支的歷史記錄。這個副作用(後面討論的另一個副作用)是Git不能再接受你的推送,因爲它不知道如何將新的截斷分支與遠程版本相關聯。所以,你需要強制推送覆蓋:

git push --force origin develop 

我提到的另一個副作用,這是改寫develop歷史也會引起問題的人在你的團隊,誰恰巧共享這個分支一樣,當他們拉。

大多數情況下,對於共享分支,最好做一個git revert而不是用硬重置覈實提交。檢查文檔或堆棧溢出以瞭解如何還原一系列提交。

+0

9分鐘到一個綠色的checkie。 –

相關問題