2011-06-01 35 views
1

我有一個情況我:的git - 推只有最頂層的承諾服務器

(1)由用戶合併補丁X
(2)做了一些修改一些其他的代碼並提交。

現在我想推我的提交到服務器。然而,當我做

git push origin HEAD:refs/for/mybranch 

我得到一個錯誤,關於我合併的補丁,說我不是作者。有沒有辦法做我想要完成的事情?如果沒有,是否有辦法保存我的提交,然後恢復所有內容並將我的提交返回?

回答

1

二修訂:

git reset --soft HEAD^ (to undo your commit) 
git stash (to stash away your changes) 
git reset --soft HEAD^ (to undo the merge commit from X) 
git stash (stash away X) 
git stash apply [email protected]{1} (apply your changes) 
git add . (add and commit and push ..) 
git commit -m "some changes" 
git push 
git stash apply [email protected]{0} 

修訂的答案:

好了,那麼你就需要一步復位更早在歷史:

git reset --soft HEAD^ (to undo your commit) 
git stash (to stash away your changes) 
git reset --hard HEAD^ (to undo the merge commit from X) 
git stash apply (apply your changes) 
git add . (add and commit and push ..) 
git commit -m "some changes" 
git push 
git merge featureX (re merge the changes from X) 

原來的答覆:

你可以你的頭復位,使你的提交被移動到索引:

git reset --soft HEAD^ 

現在git將處於合併代碼的狀態,並且您的更改未提交併準備再次上演。現在,您可以藏匿這些變化:

git stash save "stashing commit for changes from X" 

現在你可以從X向上推合併修改後適用的藏匿處,添加並提交:

git push 
git stash apply 
git add . 
git commit -m "some stuff" 
+0

有趣。但是,我不想推動X的變化。這只是我需要保留的臨時代碼,所以我也不想完全刪除它。我只是不想推它...只推我的承諾。任何解決方法? – DarezGhost 2011-06-01 19:46:56

+0

我修改了一下我的答案。當然這可以做到。 – ralphtheninja 2011-06-01 19:53:43

+0

謝謝,所以它看起來像我將不得不從X再次找到補丁:(這是我所害怕的,但我想這是唯一的方法來做到這一點 – DarezGhost 2011-06-01 20:05:41

0

爲什麼不只是提交補丁,然後分別將您的「更改爲其他代碼」? Git說的是實話,你不是補丁的作者,「用戶X」是。

此外,有沒有你正在做這個命令的理由:

git push origin HEAD:refs/for/mybranch 

,而不是僅僅

git push origin mybranch 
+0

該補丁已經提交,但我不想推它。我只是想保留它並且只推送我的提交。 – DarezGhost 2011-06-01 19:48:00

0

聽起來回購有一定的掛鉤設置其中阻止您推送您不是作者/提交者的任何提交。

您可以嘗試挑選提交,以便提交者被設置爲您。如果這不起作用,那麼你需要詢問誰安裝了存儲庫鉤子,因爲它幾乎破壞了所有的git工作流程,因爲你永遠無法推送合併提交。