Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git option for `--preserve-merges`?

Tags:

git

git-merge

Is there an option to make git do rebase with --preserve-merges by default? I know about aliases but I dislike the idea to remember their names and also it makes everything harder to do on someone else's computer when you get used to them.

like image 769
Denys Mikhalenko Avatar asked Feb 22 '17 04:02

Denys Mikhalenko


People also ask

What is preserve merges during rebase?

Git's documentation for the rebase command is quite brief: --preserve-merges Instead of ignoring merges, try to recreate them. This uses the --interactive machinery internally, but combining it with the --interactive option explicitly is generally not a good idea unless you know what you are doing (see BUGS below).

How do you conclude a merge?

After a git merge stops due to conflicts you can conclude the merge by running git merge --continue (see "HOW TO RESOLVE CONFLICTS" section below).

How does git rebase handle merge commits?

By default, a rebase will simply drop merge commits from the todo list, and put the rebased commits into a single, linear branch. With --rebase-merges, the rebase will instead try to preserve the branching structure within the commits that are to be rebased, by recreating the merge commits.

Does rebase keep changes?

After starting a rebase, Git creates an anonymous branch and starts applying commits to it. Since ours means "keep changes from the current branch", that current branch will be HEAD , which contains upstream and any changes already applied by rebase .


2 Answers

If you want to do this when you pull (say, develop), you can do this in git >= 1.7.9::

git config pull.rebase preserve

It will make all your pull actions to rebase the branch from remote into your local one and preserve merges.

It does not work if you want to rebase develop into another branch.

In git < 1.7.9:

git config --global branch.autosetuprebase always

See Make git pull --rebase preserve merge commits

like image 58
Droom Avatar answered Sep 23 '22 17:09

Droom


This kind of idiosyncratic need is one of the reasons shell functions exist.

git() {
    case $1 in
    rebase) shift; set -- rebase --preserve-merges "$@" ;;
    esac
    command git "$@"
}

As for

I know about aliases but I dislike the idea to remember their names and also it makes everything harder to do on someone else's computer when you get used to them.

I think a method for getting a command to behave differently on someone else's computer, but only when you use it, would have to be asked as a separate question for a proper response.

like image 44
jthill Avatar answered Sep 23 '22 17:09

jthill