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?
Asked
Active
Viewed 1.1k times
24

Jacob Krieg
- 2,834
- 15
- 68
- 140
-
Some of them or all of them? Do the repos have a common ancestor or are they completely independent? – Aaron Digulla Sep 27 '13 at 08:12
-
1The plug-in should have been developed in a branch. Interesting question. Considering how powerful git is, there probably is an answer. – Vorac Sep 27 '13 at 08:13
-
2He can simply export the whole plugin repo as patches and then apply them to the project's repo. – Aaron Digulla Sep 27 '13 at 08:30
-
@Aaron Digulla All of them. The repos don't have a common ancestor, they are completely independent. – Jacob Krieg Sep 27 '13 at 13:28
-
@Vorac I agree, but I didn't know the plug-in would be included in the main project, this is why this situation occurred. – Jacob Krieg Sep 27 '13 at 13:28
-
@Aaron Digulla "He can simply export the whole plugin repo as patches and then apply them to the project's repo". By doing this i would lose the commits which i need :( – Jacob Krieg Sep 27 '13 at 13:30
-
@JasonSwartz: I'm sure git has a feature to export commits as a file which you can then import in another repo. – Aaron Digulla Sep 27 '13 at 14:12
-
possible duplicate of [Import another commit to my repo](http://stackoverflow.com/questions/11135943/import-another-commit-to-my-repo) – peschü Nov 17 '14 at 09:00
-
Possible duplicate of [How to import existing Git repository into another?](https://stackoverflow.com/questions/1683531/how-to-import-existing-git-repository-into-another) – Eugen Konkov Jan 24 '18 at 08:40
1 Answers
33
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 (see cherry-pick documentation):
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.
-
1After `git remote add plugin ...` you also need to do `git fetch plugin` otherwise the hashes will not be in your local repository yet. – peschü Nov 17 '14 at 08:53
-
-
If it is a one time thing then it can be simplified to `git fetch ../path/to/plugin/repo`, `git remote add` is not needed, – NiKiZe Aug 30 '21 at 06:27
-
after fetch, I did `git checkout ....` which was easier for me personally. Oh and `git pull --allow-unrelated-histories` – Sridhar Sarnobat Sep 05 '22 at 18:05