Reputation: 2639
I have to make a merge between repositories. I was working with some people in project A.
Once we finished project A, we started the project B.
Project B has project A as base so we cloned A removed the git files and started working with this files (I don't really know why we did this there were lots of better ways to do that)
So now I have Project A with all of its commits and Project B with an initial commit that includes the whole A and the ones we did working in B
Is there any possibility to move commits from repository B to repository A? (excluding the first one which is the project A)
Upvotes: 2
Views: 48
Reputation: 41945
rep A:
a1 --- a2
rep B:
b1 --- b2
The problem here is that a2 and b1, although they have the same content, are not the same commit since they have different ancestry.
Here the very simple example I made, fetching the branch from another repo. git
creates a branch with a detached branching point:
mkdir a
cd a
echo "a1" > asdf.txt
git init
git add asdf.txt
git commit -m"a1"
echo asdf2 >> asdf.txt
git commit -am"a2"
cd ..
cp -a a b
cd b
rm -rf .git
git init
git add asdf.txt
echo b1 >> asdf.txt
git commit -am"b1"
echo b2 >> asdf.txt
git commit -am"b2"
git log --graph --all --oneline --decorate
cd ../a
git log --graph --all --oneline --decorate
git fetch ../b master:b_branch
git log --graph --all --oneline --decorate
results in:
* 4de3a97 (b_branch) b2
* 34c116e b1
* 4b25afe (HEAD, master) a2
* 7ac42e8 a1
It does not show in the git log --graph
, but if you visualize the repo with gitk --all
at that point, you'll see that the history is disconnected.
From there you can rebase the b_branch
on master
:
git checkout b_branch
git rebase master
Chances are you'll get a conflict for the very first commit of b_branch
(that is not in master
), but after that you should be good. Solve the conflict manually, git add
the offending file(s), then git rebase --continue
.
Upvotes: 2