I want:
- to work on
develop
and make all my changes there (or in other feature branches that are merged intodevelop
) - to merge
develop
intomaster
when I want to release (squashing all commits since the last time I did that)
But I'm getting merge conflicts when I merge develop
into master
.
Here's a small example of my workflow that reproduces what is a problem to me:
Create empty repo, clone it
bicou@dikkenek:/tmp$ mkdir repo.git bicou@dikkenek:/tmp$ cd repo.git/ bicou@dikkenek:/tmp/repo.git$ git init --bare Initialized empty Git repository in /tmp/repo.git/ bicou@dikkenek:/tmp/repo.git$ cd /tmp bicou@dikkenek:/tmp$ git clone repo.git repo Cloning into 'repo'... warning: You appear to have cloned an empty repository. done. bicou@dikkenek:/tmp$ cd repo
Now make some commits to master:
bicou@dikkenek:/tmp/repo$ echo 'blah blah blah' > readme bicou@dikkenek:/tmp/repo$ echo 'version: 1' >manifest bicou@dikkenek:/tmp/repo$ git add manifest readme bicou@dikkenek:/tmp/repo$ git commit -m "initial commit" [master (root-commit) 5c7f827] initial commit 2 files changed, 2 insertions(+) create mode 100644 manifest create mode 100644 readme
Now branch off
develop
bicou@dikkenek:/tmp/repo$ git checkout -b develop Switched to a new branch 'develop' bicou@dikkenek:/tmp/repo$ echo "testing" >work bicou@dikkenek:/tmp/repo$ git add work bicou@dikkenek:/tmp/repo$ git commit -m "working on work" [develop f22b31b] working on work 1 file changed, 1 insertion(+) create mode 100644 work bicou@dikkenek:/tmp/repo$ echo "more work" >>work bicou@dikkenek:/tmp/repo$ git commit -am "still work" [develop 6a8981f] still work 1 file changed, 1 insertion(+)
Here is a modification of a file that's already tracked on
master
:bicou@dikkenek:/tmp/repo$ sed -i 's/version: 1/version: 2/' manifest bicou@dikkenek:/tmp/repo$ git commit -am "version bump" [develop de2866b] version bump 1 file changed, 1 insertion(+), 1 deletion(-)
Back to master, merge all commits in
develop
and squash them:bicou@dikkenek:/tmp/repo$ git checkout master Switched to branch 'master' bicou@dikkenek:/tmp/repo$ git merge develop --squash Updating 5c7f827..de2866b Fast-forward Squash commit -- not updating HEAD manifest | 2 +- work | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 work bicou@dikkenek:/tmp/repo$ git commit [master 04528f9] Squashed commit of the following: version bump still work working on work 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 work
Now back to work:
bicou@dikkenek:/tmp/repo$ git checkout develop Switched to branch 'develop' bicou@dikkenek:/tmp/repo$ echo "still working" >>work bicou@dikkenek:/tmp/repo$ git commit -am "continued work" [develop 81e3d08] continued work 1 file changed, 1 insertion(+)
Then the change that in my opinion should be fine but will prove to break things:
bicou@dikkenek:/tmp/repo$ sed -i 's/version: 2/version: 3/' manifest bicou@dikkenek:/tmp/repo$ git commit -am "version bump" [develop 83b77fb] version bump 1 file changed, 1 insertion(+), 1 deletion(-)
Back to
master
, expecting a dumb merge that didn't happen:bicou@dikkenek:/tmp/repo$ git checkout master Switched to branch 'master' bicou@dikkenek:/tmp/repo$ git merge develop --squash Auto-merging work CONFLICT (add/add): Merge conflict in work Auto-merging manifest CONFLICT (content): Merge conflict in manifest Squash commit -- not updating HEAD Automatic merge failed; fix conflicts and then commit the result.
Here's one conflict:
bicou@dikkenek:/tmp/repo$ cat manifest <<<<<<< HEAD version: 2 ======= version: 3 >>>>>>> develop
So my questions/reflections:
- Why didn't it fast forward?
- I know I can force the merge with
git merge develop --squash -s recursive -Xtheirs
, but do I need to do that each time I will mergedevelop
intomaster
? - Is my workflow wrong?
- After merging
develop
intomaster
, should I merge backmaster
intodevelop
? Isn't that an infinite loop? - Why did the merge in step 5 worked when the one in step 8 didn't? It's just a change of
1
->2
(OK) and then2
->3
(KO). Should be fine for me! - Is there any merge strategy or any other option that may get me to what I want?
Bonus question:
when squashing, git is nice enough to compile all the commit messages before committing the squash. But that contains all the commit messages since the branches forked (e.g. step 3 above).
How to get only the commit messages since the last time I merged develop into master? (e.g. step 5 above)
Note: merging using a temporary branch does what I want in terms of merging without conflicts, but it doesn't in the sense where I don't have all the commit messages squashed into one.