Can i merge files in git?

I have three Shell-ijk-ArrayList.java , Shell-ijk-Vektor.java and Shell-ikj-ArrayList.java in this git repository . I "combined" them manually in MatrixMultiplication.java . Now I would like to get rid of the other three, but I want to keep their history. What is the best way to do this?

I found a git merge file , but when I try

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

I get

 error: Could not stat MatrixMultiplication.java 

I could just delete the old files with git rm , but then I will lose the history, right?

I could also move it with git mv , but what would be a good folder for obsolete files?

+6
source share
3 answers

It seems to me that you are combining different files with separate logic into one file? This is not what a git file merge is.

From git help 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. 

Example (also from the help page):

  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. 

To combine logic with completely separate files into one, you are right to combine them manually.

Deleting a file does not delete its history; you can view the log of the deleted file using

 git log -- <path_to_file> 

See related questions / answers:

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

Find and recover deleted file in git repository

+2
source

I'm not sure if the git merge file is what you need. This is more like code refactoring / shuffling.

git rm stores history and has no retroactive effect. If you revert to the previous version, they will be there. When I go and check my old checks, the "git rm" 'd files still exist with full history.

+1
source

git rm will not lose the history of these files: see " Requesting remote content in git ":

To view the commit history of this file, you cannot do this in the usual way:

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

Instead, you need to do this:

 $ git log -- file2 

As for git-merge-file , try applying it to an empty, but added to the index, MatrixMultiplication.java file.

+1
source

Source: https://habr.com/ru/post/920859/


All Articles