2012-07-19 9 views
6

나는 git-repositoryShell-ijk-ArrayList.java, Shell-ijk-Vektor.javaShell-ikj-ArrayList.java의 세 파일을 가지고 있습니다. 나는 수동으로 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

:

git log -- <path_to_file> 

는 관련 Q/A를 참조하십시오 역사를 제거하지 않는 파일을 삭제

, 당신과 삭제 된 파일의 로그를 볼 수 있습니다 정확히 어떤 방식으로 병합 하시겠습니까? 이 파일들은 서로 매우 다르게 보입니다. –

답변

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: How to search for a deleted file in the project commit history?

Find and restore a deleted file in a Git repository

+0

고맙습니다. '전복'에서 역사가 사라 졌는지 아십니까? (btw., 좋은 블로그) –

+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에 추가하십시오.

관련 문제