Git merge squash repeatedly
Starting with
X stable
/
a---b---c---d---e---f---g development
You can use the following steps to copy the last commit from your development branch to your stable branch:
git checkout development@{0} # get working tree from "development", detach HEAD
git reset --soft stable # reposition detached HEAD on "stable"
git commit # enter the appropriate commit message
git branch temp # create a temporary branch "temp" at HEAD
git checkout temp # get on the new temporary branch
git branch -M stable # rename "temp" to "stable"
so you end up with:
X-------------------G stable
/
a---b---c---d---e---f---g development
If you continue work on "development", e.g.,
X-------------------G stable
/
a---b---c---d---e---f---g---h---i---j development
you can repeat the same git commands as above and you will end up with:
X-------------------G-----------J stable
/
a---b---c---d---e---f---g---h---i---j development
This isn't the right place to use merge --squash
. One good place to use it is in a throwaway topic branch, which you're going to merge into your main branch and then get rid of. All the development done in the topic branch is shown as one commit in the main branch. In your situation, you should merge from the development branch normally, and then use git-rebase --interactive
to squash the commits you want.
Is it possible to somehow record the merge, without producing a "merge commit" with two parents?
If I understand the question correctly, no. Absolutely not.
Is it possible to tell git to merge only a certain "range" of revisions, like in SVN?
Yes. git merge [commit hash]
Or, is it possible to do a normal merge without having to download all refs from the other branch when pulling?
See answer to previous question.
Or should I provide a custom merge driver for the files in question, that simply renames "their" version to "our", thereby resolving the conflicts? I'm still afraid that --squash will always try to merge the whole history, up to the common parent, solving only half of my problem.
No! Just don't use git merge --squash
. This isn't the right place to use it!