2012-03-15 59 views
1

好的,這是故事。我們有20-30k行代碼的git倉庫。我的同事複製(複製,不移動)回購中的幾個文件來創建另一個模塊。這些文件的內容只是稍作修改。然後他做了一個承諾。與此同時,我與他複製的一些文件(原件)合作並完成了我的工作。當我拉着時,我意識到自己創建了它們(複製它們)後,我在文件中發生了衝突。在解決了衝突之後,我檢查了我的本地回購協議,並且沒有我想要的一半文件。我知道git跟蹤文件的內容,而不是文件名,但現在它不是很有幫助。Git repo中的類似文件之一在副本後消失

git log remote_repo --stat --diff-filter=D 

表明,一些文件被刪除,

git log remote_repo --stat -C --diff-filter=D 

顯示較少的文件被刪除了(但仍有一些)

我們需要兩個文件副本所以,我們應該怎麼辦?

回答

1

您需要重新綁定並嘗試再次解決衝突。這可能很簡單,也可能稍微複雜一些。如果它很簡單,您只需要重新合併並修復已刪除的文件。試試這個:

git rebase -i HEAD~1 

你會看到一個屏幕,詢問你想要對每個提交做什麼。 這將是這樣的:

pick bb009b7 merge commit 

# Rebase 9775146..bb009b7 onto 9775146 
# 
# Commands: 
# p, pick = use commit 
# r, reword = use commit, but edit the commit message 
# e, edit = use commit, but stop for amending 
# s, squash = use commit, but meld into previous commit 
# f, fixup = like "squash", but discard this commit's log message 
# 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# However, if you remove everything, the rebase will be aborted. 
# 

變化挑編輯,保存並退出編輯器。您現在又回到合併提交中。運行:

git checkout <id of the previous commit> <filename> 
git commit --amend 
git rebase --continue 

這應該解決它。如果不這樣做,則需要進一步回溯,可能會更復雜。

我猜想,它會去是這樣的:

# rebase the last three commits, assuming: 
# the oldest is your most recent changes 
# the next is your co-worker's 
# the last is the merge 
# You can probably go back only two but I generally 
# go back one extra just to see that things are as I 
# expect. 

git rebase -i HEAD~3 

你會看到一個對話框,詢問呈現你想要做的每一個承諾什麼。 這將是這樣的:

pick 8d25cf0 Your changes 
pick e9ddd29 His changes 
pick bb009b7 merge 

# Rebase 9775146..bb009b7 onto 9775146 
# 
# Commands: 
# p, pick = use commit 
# r, reword = use commit, but edit the commit message 
# e, edit = use commit, but stop for amending 
# s, squash = use commit, but meld into previous commit 
# f, fixup = like "squash", but discard this commit's log message 
# 
# If you remove a line here THAT COMMIT WILL BE LOST. 
# However, if you remove everything, the rebase will be aborted. 
# 

假期第一行是。在第二個改變選擇編輯。最後我想你也要編輯。

編寫並保存這個,並且rebase將開始。它將通過第一次提交併在第二次停止。你的文件應該丟失。您現在想運行:

git checkout <id of the previous commit> <filename> 

而且這將恢復您的同事刪除的文件。

然後運行:

git commit --amend 
git rebase --continue 

當你到了合併提交只是檢查,以確保事情像您期望。如果文件丟失,請嘗試再次檢出。然後修改並繼續。你現在應該擁有你需要的一切。

如果你覺得事情在任何時候

git rebase --abort 

會錯這將使你回到你開始的地方,你可以再次嘗試。

+0

所以你說的是我需要重新綁定並強制推送到我們的遠程倉庫,並且還告訴所有參與者放棄並再次拖動這個分支? – 2012-03-15 17:36:38

+0

我想你可以嘗試在當前提交中執行前一個提交> git checkout ',只要在沒有這些文件的情況下提交歷史記錄不會被視爲問題。 – Ilion 2012-03-15 17:47:33

+0

我寧願有這些文件的歷史記錄,所以一旦我將重新開始工作,我將首先嚐試重新綁定。 – 2012-03-15 18:04:16

相關問題