2012-07-19 18 views
6

git-repositoryには、Shell-ijk-ArrayList.java,Shell-ijk-Vektor.javaShell-ikj-ArrayList.javaという3つのファイルがあります。私は手動でMatrixMultiplication.javaに「マージ」しました。今私は他の3つを取り除きたいと思っていますが、私は彼らの歴史を残したいと思います。これを行う最善の方法は何ですか?gitでファイルをマージできますか?

私はgit merge-fileを発見したが、私は

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

をしようとしたとき、私は、私は単にgit rmと古いファイルを削除することもできますが、その後、私は歴史を失う

error: Could not stat MatrixMultiplication.java 

を取得し、」勝ちました私は?

私はgit mvで移動することもできますが、古いファイルの場合はどのようなフォルダが適していますか?

+0

ファイルを削除

は、その歴史は削除されません、あなたが削除されたファイルのログを見ることができますどんな方法でそれらをマージしますか?これらのファイルは、お互いに非常に異なって見えます。 –

答えて

2

別々のロジックを持つ別々のファイルを1つのファイルにマージするように見えますか?これは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のヘルプマージファイルから

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。、nice Blog) –

+0

http://stackoverflow.com/questions/497670/whats-a-simple-way-to-undelete-a-file-in-subversion –

1

git merge-fileが必要なのはわかりません。これは、コードのリファクタリング/シャフリングのように聞こえます。

git rmは履歴を保持し、遡及しません。以前のバージョンに戻すと、そこに表示されます。私が行って、私の古いチェックインをチェックすると、私は "git rm"というファイルがまだ完全な履歴とともに残っています。

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に追加してください。