Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Q] Why can't i merge next into master? #5

Closed
emahuni opened this issue Aug 27, 2018 · 3 comments
Closed

[Q] Why can't i merge next into master? #5

emahuni opened this issue Aug 27, 2018 · 3 comments
Labels
question Further information is requested

Comments

@emahuni
Copy link

emahuni commented Aug 27, 2018

I remember you mentioning this in your tute, but you didn't explain why.

Ok, I have the four branches and I have created a topic and all went well. Then I went thru pu and then next processes. Did the same to other nine topics and eventually had 10 of them.

Now we want to cut a release after CI passes on next. If I got it right you said master and next never merge nor does pu and next nor pu and master. It means I have to merge those topic branches one by one into master, so why not just merge next into master seeing that is the state of the project we want to release?

This is similar in concept to GitFlow’s release branch, but far more flexible and powerful, since master has no dependencies on next whatsoever, nor is next ever merged wholesale into master (unlike the corresponding GitFlow branches develop and release).

The keyphrase here is:

nor is next ever merged wholesale into master

What's wrong with that since they all have a common ancestor?
Will something bad happen when we reset next and pu to master?
Is there a caveat in git checkout master && git merge --no-ff next && git checkout next && git reset --hard master approach, when the state of next branch is what we want to release?

@emahuni
Copy link
Author

emahuni commented Aug 27, 2018

I am doing this manually so that I understand what you were talking about without using your aliases.

kkkk just noticed one reason why one should not do this or actually why you may want to do this. When the pu/next branches are merged into master, the default merge log messages that say "merged blah/topic into next" will remain in the log history. I think this can be used for posterity to know if a topic went thru the normal cycle if so desired, but it is not as clean as when the topic branches mergers are done on the master branch directly.

The only problem I was having was the order of the merges. Actually I noticed that I had to do the merges in the order they were done in the working next branch otherwise some unexpected changes will happen to the code. eg if you have two topics' commits that do changes to the same file and you commit the last commit first and the earlier one last, it will remove the changes that the later commit does and leave the working tree unclean. To get around it I just followed the merge commits as they happened in next. Whether I to do them one by one or as a group of commits in a single merge, I had to do them in that order i see in git lg next log.

But maybe you could give a more educated reason why one should not merge next or pu directly onto master.

@rocketraman rocketraman added the question Further information is requested label Aug 27, 2018
@rocketraman rocketraman changed the title Why can't i merge next into master? [Q] Why can't i merge next into master? Aug 27, 2018
@rocketraman
Copy link
Owner

@emahuni Yes, I would say the primary reason is to keep the log --first-parent history of master clean -- if you merge next into master, in order to find the specific topic branches merged, you will have to dig one level deeper than a simple log --first-parent master (you'd have to do that on the merge commit in turn i.e. log --first-parent <merge-commit>).

Merging the individual topics into master also gives you the option to skip merging one or more of them. However, it is not unusual to want to merge every topic in next into master. This is easily scripted:

# using `mergedinto` alias, this keeps the merge commit order, but removes dups i.e.
# merge A, merge B, then merge A, becomes merge A, B -- in my experience this works well
# https://gist.github.com/rocketraman/1fdc93feb30aa00f6f3a9d7d732102a9#file-gitconfig-L60
git mergedinto master..next > /tmp/branches

# fish shell syntax
while read x
  echo "Merging $x"
  # mb (merge-branch) is another alias I use to avoid having to pull all the topic branches down locally
  # but otherwise this is a simple `merge --no-ff`
  # https://gist.github.com/rocketraman/1fdc93feb30aa00f6f3a9d7d732102a9#file-gitconfig-L14
  git mb $x; or break
end < /tmp/branches

The subsequent command has to be run multiple times in case of intermediate conflict resolutions -- however it works well as a repeatable idempotent command (git reports "up-to-date" for branches already merged).

Another tip: if you were not the one to do all the merges into next, before running the command above, train your local rerere cache from next to repeat the same conflict resolutions when merging to master:

bash ~/source/git.git/contrib/rerere-train.sh -o master..next

This is the kind of thing for which we should add scripts into this repo, but I'd like them to soak and/or get feedback from people such as yourself before doing that. Let me know how it goes.

@emahuni
Copy link
Author

emahuni commented Sep 1, 2018

oh ok. just what i was after.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants