Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Import commits from a repo to another repo

Tags:

git

I have a big Git repository for a project for which I created a plug-in which also is source controller with Git. Recently I copied the plug-in's folder to the main project folder. Now I have a project folder source controlled with Git and the plug-in's folder which is also source controlled with Git. My question is, is there a way to import the commits from the plug-in's repository to the main repository so I can get rid of the plug-in's .git folder?

like image 968
Jacob Krieg Avatar asked Sep 27 '13 08:09

Jacob Krieg


People also ask

Can I copy a commit from one repo to another?

Yes. You can place your LICENSE commit as the first commit by rebasing. Rebasing is gits way of rearranging commit order while keeping all the commit authors and commit dates intact. When working on a shared repo, it's generally discouraged unless your entire team is git-fluent.

How do I pick a commit to another repo?

It is possible to cherry pick from another repo using the command line. You will first need to add the other repository as a remote and then fetch the changes. From there, you should be able to see the commit in your repo and cherry pick it.

How do I commit code from one git repo to another?

We will use git cherry-pick , which is a git command to get commits from another branch or repository. In order to get commits from the other repository, You'll need to add the other repository as a remote, then fetch its changes. From there you see the commit and you can cherry-pick it.

How do I push changes from one repo to another?

To push the commit from the local repo to your remote repositories, run git push -u remote-name branch-name where remote-name is the nickname the local repo uses for the remote repositories and branch-name is the name of the branch to push to the repository. You only have to use the -u option the first time you push.


1 Answers

Open a command window in the project folder.

Make sure you're on a branch. e.g. git checkout -b plugin-history

Add the plugin folder as a remote: git remote add plugin ../path/to/plugin/repo

Fetch the hashes from the new remote: git fetch plugin

Bulk cherry-pick all the plugin history from the remote branch:

git cherry-pick firstSha1^..mostRecentSha1

(There are more instructions about cherry-picking multiple commits here: How to cherry-pick multiple commits)

You should then have all the history as new commits on the plugin-history branch.

like image 58
ChrisA Avatar answered Oct 13 '22 08:10

ChrisA