Reputation: 31130
Say I have:
Commit 5 < HEAD
Commit 4
Commit 3
Commit 2
Commit 1
I want to Push (Commit 5) to different repo WITHOUT commits 2,3,4. Is that possible?
The reason why I need it:
I have 2 projects:
While working on my (Project-1) I might need to do some changes to the (Starter).
What I currently have is 2 remotes in (Project-1):
origin
pointing to the private (Project-1) repository.starter
pointing to the open sourced (Starter) repository.Normally while working in (Project-1) I push all my commits to the origin master branch.
However, when I do changes to the (Starter) I commit them alone and I try to push that specific commit Commit 5
to the (Starter) repository. This is working fine! using the git push starter c78d92e32ec1a:master
.
But the problem is when I push Commit 5
it also push all the previous commits (2,3,4), which in my case are related to the (Project-1).
Is it logically possible to only push specific commit even if it's not the last one. Example merge Commit 4
with (Starter) repo.
Upvotes: 1
Views: 1432
Reputation: 31130
OMG it's working
checkout the master branch (git checkout master)
work on the master branch normally
work on the starter code and commit as well "the part of the code that is reusable and beneficial for the starter to have” {just careful to never include project code with your starter commits}
READY TO SEE THE MAGIC!
Upvotes: 0
Reputation: 40861
Git is very well suited for what you're trying to achieve, however I'm afraid you should reorganize a bit.
Given the information in your question, you only have one branch and two remotes for two distinct projects. You want two different branches.
Start by checking out the most recent commit for starter that does not have parent commits of Project-1.
git checkout Commit1SHA
Create a new branch for your starter project, and set it to track starter master.
git checkout -b stmaster
git branch stmaster -u starter/master
For this time only, we can fix up the tree with a cherry pick, but things will be cleaner moving forward.
git cherry-pick Commit5SHA
Now a push will only send commits 1&5 to starter
git push
From here out, you're setup for a good rebase strategy to keep your merge lines tidy. You can continue working on Project 1, making commits, and pushing normally.
git checkout master
echo "hello world" > newfile.txt
git add .
git commit -m "create hello world"
git push
Now when you want to make changes to starter, checkout that branch for work.
git checkout stmaster
echo "starter changes" > more.txt
git add .
git commit -m "create more changes"
git push
Now rebase those changes into project 1 to keep commit lines straight.
git checkout master
git rebase stmaster
git push
Upvotes: 2