Currently, before merging a branch, I use the following commands to see what changes will be merged:
base=$(git merge-base other HEAD)
git diff $base other
Is there a single git command to achieve this?
Regards, Jochen
General tools. The status command is in frequent use when a working with Git and during a merge it will help identify conflicted files. Passing the --merge argument to the git log command will produce a log with a list of commits that conflict between the merging branches.
You can use the git merge-base command to find the latest common commit between the two branches. If that commit is the same as your branch head, then the branch has been completely merged.
You just need to check the length of the `parents`. If there are two or more commits, it's a merge commit, otherwise it's a regular commit.
The most basic and powerful tool to do this is the git log command. By default, with no arguments, git log lists the commits made in that repository in reverse chronological order — that is, the most recent commits show up first.
git diff ...other
Note: the question "How can I preview a merge in git?" does mention the context of seeing what would be merged when fetching:
[alias]
# fetch and show what would be merged (use option "-p" to see patch)
incoming = "!git remote update -p; git log ..@{u}"
With:
- "
git incoming
" to show a lot of changes, or- "
git incoming -p
" to show the patch (i.e., the "diff"),- "
git incoming --pretty=oneline
", for a terse summary, etc
You can find more elaborate scripts in this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With