Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Additional changes in a merge commit

Tags:

git

Let's say I'm merging a pull request and want also to accompany the merge with a line in the changelog:

> git merge --no-ff otherguy/feature-x
> echo "Feature: X" >> changelog
> git commit -am "Changelog update"
> git push

A similar thing is possible in a single commit:

> git merge --no-ff --no-commit otherguy/feature-x
> echo "Feature: X" >> changelog
> git commit -am "Merge otherguy/feature-x + changelog"
> git push

So that the same commit will contain both the merge and the file changes.

Granting that I always update the changelog when merging from the downstream repositories, here is a question:

Is the latter way a sane thing to do and what unexpected consequences might show up later?

Update: As for why I need a separate file changelog when I already have a git log, the one in the file is more pruned (entry or so per merge, not per commit), sometimes better worded and in a certain format (e.g. debian/changelog). So, it's for external usage.

like image 540
bereal Avatar asked Jan 16 '13 08:01

bereal


People also ask

Can I amend a merge commit?

Updated answer for 2020:You can then edit the merge commit as desired via git commit --amend . Find the merge commit you want to edit in the todo list. Insert a new line after the merge commit that contains only break (or b ). Use git commit --amend to edit the merge commit as desired.

How do I amend a merge commit message?

If the commit only exists in your local repository and has not been pushed to GitHub.com, you can amend the commit message with the git commit --amend command. On the command line, navigate to the repository that contains the commit you want to amend. Type git commit --amend and press Enter.

Does git merge overwrite changes?

Usually git does not overwrite anything during merge.

Can I still add commit on branch after created merge request?

Yes you can being on a new branch doesn't stop you from using a commit.


1 Answers

You should first consider if it really is useful to keep a changelog committed in the repository, when you have git there to keep the changelog in the first place.

Also, adding things in merge that didn't exist in either branch is called an evil merge, and is not a good practise anyway.

like image 155
Kalle Pokki Avatar answered Sep 26 '22 01:09

Kalle Pokki