سؤال

Is there a way to have git always merge without a fast-forward, except for when pulling?

Following a nice git-flow, I like keeping my branch history (easier to remove features, etc later on), so I have set my config to never fast-forward when merging, like so:

git config --global merge.ff false

However, whenever I update my current branch/pull from the remote, it creates a merge commit... which is really gross, especially for forking other projects on GitHub.

Is there anyway to make a git pull always fast-forward? Unfortunately, I tried doing:

git pull --ff-only upstream master

... only to watch it spit out an error:

fatal: You cannot combine --no-ff with --ff-only.

I'm really tired of seeing this:

Gross: a "git pull" merge commit

هل كانت مفيدة؟

المحلول

You can try this:

git pull --rebase upstream master

This will rebase your commits on top of upstream commits.

Here is an illustration of what it does.

Your local repository:

* bbbbbbb (HEAD, master) My changes.
* aaaaaaa Initial commit.

Upstream repository:

* ccccccc (upstream/master) Their changes.
* aaaaaaa Initial commit.

After git pull --rebase upstream master:

* bbbbbbb (HEAD, master) My changes.
* ccccccc (upstream/master) Their changes.
* aaaaaaa Initial commit.

نصائح أخرى

I'd suggest you to work in a separate branch and keep rebasing onto the remote branch instead of merging.

Change:

$ git checkout -b my-topic-branch
$ (work work work)
$ git commit
$ git checkout master
$ git pull origin master
$ git merge my-topic-branch

By:

$ git checkout -b my-topic-branch
$ (work work work)
$ git commit
$ git fetch origin
$ git rebase origin/master
$ git checkout master
$ git merge my-topic-branch

If that combination of configurations don't work, I think you're left with that.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top