2016-01-23 69 views
0

考慮我有A,B,C,D提交併將它們推送到遠程回購。如何將缺失的文件添加到提交?

提交後D我發現有一個文件應該在B提交。

如何編輯B提交併添加缺少的文件?

+2

的可能的複製[如何修改指定的通訊它在混帳?](http://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit-in-git) –

回答

1

這將工作假設沒有人從遠程拉代碼。如果發生這種情況,你的歷史不再是你的,這是一個壞主意。

  1. 確保您的回購是乾淨的。
  2. git rebase -i A
  3. 在您的編輯器中,更改B的條目進行編輯。
  4. 通過關閉編輯器來啓動rebase。 git將停止在B
  5. git add file(其中file是要添加的文件)。
  6. git commit --amend。修復提交消息並提交
  7. git rebase --continue以獲取其他的提交後期。
  8. git push --force
0

您可以使用作爲交互式底座的壁球。你只需要記住rebase的結果。 任何擁有該分支副本的人都必須將其刪除並重新獲取,因爲您的歷史記錄已更新。

一旦完成重寫歷史記錄,您將不得不刪除遠程分支或使用-f來強制推送。


爲了做一個git壁球遵循這些步驟:

// X is the number of commits you wish to squash 
git rebase -i HEAD~X 

一旦你壓扁你的提交 - 選擇e編輯的所需提交的內容,進行更改並提交。在你的情況下,將缺失的文件添加到B提交中。

enter image description here


你也有--root標誌的情況下,你需要它

嘗試:git rebase -i --root

--root

Rebase all commits reachable from <branch>, instead of limiting them with 
an <upstream>. 

This allows you to rebase the root commit(s) on a branch. 
When used with --onto, it will skip changes already contained in `<newbase>` 
(instead of `<upstream>`) whereas without --onto it will operate on every 
change. When used together with both --onto and --preserve-merges, all root 
commits will be rewritten to have `<newbase>` as parent instead.` 
相關問題