Move the directory to the git repository to another git repository, preserving part of the commit history

I set aside the existing git ( originalrepo) repository on my own github, called this repo myrepo.

I edited two or three files in a specific directory here, say mydir.
However, mydirit is not located directly in myrepo, instead it is similar to myrepo/dirA/dirB/mydir.

Now my group has set up a separate git repository called grouprepo, and I want to move the files that I worked on this new repo.

I want to transfer it directly to grouprepo/mydirand save the commit history, but only those commits that I made (not including thousands of commits from originalrepo), and only move the files to which I made changes.

Is it possible? If so, how?

+4
source share
1 answer

You can do this very simply:

  • Add a second start to your new project, pointing to the "old"
  • select the necessary commits

    # Add the reference to the old project where your commits are
    git remote add origin2 < url>
    
    # get all the data from all the repositories
    git fetch --all --prune
    
    # Now checkout the branch you want to add your previous commit to
    git checkout <branch>
    
    # "pick" the desired commits you want
    git cherry-pick commit1 commit2 ... commit
    

And you are all set up, and your commits (and only them) are in your current branch.


cherry-pick

select which commits (from any branch or may even be a free commit) select this commit and put it in my current branch, in other words - make any commit from anywhere in the repository, add it to my branch


enter image description here

cherry-pick
(im , .)

enter image description here

0

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


All Articles