I forked off an existing git repo ( originalrepo
) onto my own github, let's call this repo myrepo
.
I edited two or three files in a certain directory here, say mydir
.
However, mydir
is not located directly in myrepo
, instead it's something like myrepo/dirA/dirB/mydir
.
Now my group has set up a separate git repo called grouprepo
and I want to move the files that I worked on to this new repo.
I want to move it directly to grouprepo/mydir
and preserve the commit history, but only the commits that I did (not including thousands of commits from originalrepo
) and only move the files that I made changes to.
Is this possible? If so, how?
You can do it very simple:
pick up the relevant commits you need
# 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 and your commits (and only them) are in your current branch.
cherry-pick
choose which commits (from any branch or even can be loose commit) pick this commit and place it in my current branch, in other words - take any commit from anywhere in the repository add bring it to my branch
Retrieving all the content of all the remotes
cherry-pick
the desired commits into the current branch
(im my case there is a conflict but it makes no difference.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.