Reputation: 33817
I have origin/master
with the main code and my own local development
branch. When I am done in development, I want to merge the outcome to master
and push to origin
.
My local git looks like that:
* 5555 (HEAD, origin/master master) merged development, master code v 2
|\
| * 4444 (development) some
| * 3333 feature
| * 2222 added
|/
* 1111 master code v 1
When I do git push
on master
I would like the origin/master
to have only commits: 1111
and 2222
, so it would look like:
* 5555 (HEAD, master) merged development, master code v 2
* 1111 master code v 1
But when I do git push origin mainline
then all three commits from development are pushed as well.
Edit
merge
or merge --squash
, My question is only about pushing the "main" commit path, without development
trashUpvotes: 1
Views: 385
Reputation: 7944
Interactive rebase is an overkill in this simple case. I find git reset --soft
a simpler and faster solution:
git reset --soft 1111
All your changes from 2222, 3333, 4444 are uncomitted now, but staged and will be added to commit. Verify if everything is correct and then
git commit -m "<Insert your meaningful commit message here>"
Upvotes: 2
Reputation:
I think you might have typos in your question, but it sounds like you just want to have all the work done in development
merged into master
as one commit, is that correct? If that is the case, then you can simply squash the commits on your development
branch into one commit, then merge them into master
:
git checkout development
git rebase -i HEAD~3
# After done squashing
git checkout master
git merge development
git push origin master
Or, as @akaRem suggests in his answer, you can simply do a soft or mixed reset on the development
branch and re-commit all the changes as one commit:
git checkout development
git reset --soft 1111
git commit
git checkout master
git merge development
git push origin master
Upvotes: 2
Reputation: 77059
In your development branch do git rebase -i 2222
. Your editor will open with content like:
pick 2222 added
pick 3333 feature
pick 4444 (development) some
Change the last two lines to start with 'f' for fixup:
pick 2222 added
f 3333 feature
f 4444 (development) some
Save and exit the editor. Look at your log now:
$ git log --oneline
pick 2345 added
pick 1111 master code v 1
The lastest commit is now a combination of the three changes in your branch. You can now proceed to cherry-pick that change into master:
git checkout master && git cherry-pick 2345
or you can rebase master into your branch and then merge back into master:
git rebase master && git checkout master && git merge development
The end result will be much the same.
If you use a shared repository model, this workflow will result in your local development branch being divergent from your remote development branch. You can reset your local development branch after making these changes, or use a temporary branch to do the rebase. (If you intend to keep the branch around at all.)
Upvotes: 1
Reputation: 7618
You may try to do git --reset ...
, then commit changes in one commit and push it to origin
Upvotes: 1