2012-07-19 91 views
6

我在這git-repository有三個文件Shell-ijk-ArrayList.java,Shell-ijk-Vektor.javaShell-ikj-ArrayList.java。我已經將它們手動合併到MatrixMultiplication.java。現在我想擺脫其他三個,但我想保留它們的歷史。做這個的最好方式是什麼?我可以在git中合併文件嗎?

我發現git merge-file,但是當我嘗試

git merge-file MatrixMultiplication.java Shell-ijk-ArrayList.java Shell-ijk-Vektor.java 

我得到

error: Could not stat MatrixMultiplication.java 

我可以簡單地用git rm刪除舊文件,但後來我將失去歷史,榮獲」我呢?

我也可以將它與git mv一起移動,但是對於過時的文件,這會是一個不錯的文件夾?

+0

以什麼方式合併它們?這些文件看起來非常不同。 – 2012-07-19 06:20:18

回答

2

它看起來像我正在合併不同的文件與單獨的邏輯到一個文件?這不是git merge-file的用處。

混帳幫助合併文件

git merge-file incorporates all changes that lead from the <base-file> to 
<other-file> into <current-file>. The result ordinarily goes into 
<current-file>. 

git merge-file is useful for combining separate changes to an original. 
Suppose <base-file> is the original, and both <current-file> and <other-file> 
are modifications of <base-file>, then git merge-file combines both changes. 

實例(也幫助頁):

git merge-file README.my README README.upstream 
     combines the changes of README.my and README.upstream since README, 
     tries to merge them and writes the result into README.my. 

從完全獨立的文件組合邏輯成一個,你是正確的手動組合它們。

刪除文件不會刪除它的歷史,可以看到已刪除的文件將與日誌:

git log -- <path_to_file> 

見相關Q/A:

Git: How to search for a deleted file in the project commit history?

Find and restore a deleted file in a Git repository

+0

非常感謝。你知道歷史是否在'顛覆'中失去了嗎? (btw。,好博客) – 2012-07-19 07:25:33

+0

http://stackoverflow.com/questions/497670/whats-a-simple-way-to-undelete-a-file-in-subversion – 2012-07-19 08:24:44

1

我不確定git merge-file是你需要的。這聽起來更像代碼重構/洗牌。

git rm保持歷史記錄,並且是非追溯性的。如果你恢復到以前的版本,他們將在那裏。當我去檢查我的舊支票時,我「git rm」'd的文件仍然有完整的歷史記錄。

1

git rm不會失去這些文件的歷史記錄:見「Querying deleted content in git」:

要查看提交該文件的歷史,你不能這樣做通常的方式:

$ git log file2 
fatal: ambiguous argument 'file2': unknown revision or path not in the working tree. 
Use '--' to separate paths from revisions 

相反,你需要這樣做:

$ git log -- file2 

至於git-merge-file,嘗試將它應用於一個空的,但添加到索引MatrixMultiplication.java文件。

相關問題