Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
221 views
in Technique[技术] by (71.8m points)

Is git set 'git pull' with rebase by default for now? Which version when it start?

In the past, git pull is doing git fetch and git merge.So it always have merge commit.

But now I saw our team members, use 'git pull' when they have commits. And won't have merge commit, because the commit time is later than the branch's last commit.

I have check the git config --list and it has rebase.autosquash=true.

Is git set git pull with rebase by default for now? Which version when it start?

question from:https://stackoverflow.com/questions/65948283/is-git-set-git-pull-with-rebase-by-default-for-now-which-version-when-it-star

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In the past, git pull is doing git fetch and git merge.

This is still the default.

So it always have merge commit.

This, however, is not the case: git merge with no options defaults to doing a fast-forward operation instead of a merge, whenever this is possible. A fast-forward operation is not a merge (even though Git refers to it as a "fast-forward merge") so it does not produce a merge commit.

You get a merge commit when:

  • you force git merge to make one, using --no-ff; or
  • a fast-forward is not possible (in which case --no-ff, if you set it, is redundant).

This is all quite configurable, though.

But now I saw our team members, use 'git pull' when they have commits. And won't have merge commit, because the commit time is later than the branch's last commit.

The word because here is misplaced. The time stamps on any given commit are quite independent of whether Git uses a merge commit. There is no cause-and-effect relationship here. Merging uses the commit graph, not any date-and-time-stamps on commits; the date-and-time-stamps are irrelevant to the graph structure.1

I have check the git config --list and it has rebase.autosquash=true

That affects git rebase: it makes a plain git rebase -i act as though you ran git rebase --autosquash -i. See the git config documentation and search for rebase.autoSquash.

To make git pull act as if you had run git pull --rebase, there are multiple configuration options:

  • branch.name.rebase can be set to anything that evaluates to boolean true;
  • pull.rebase can be set to anything that evaluates to boolean true.

In addition, setting branch.autoSetupRebase directs branch-name-creating operations to set branch.name.rebase to true. Again, see the configuration documentation for details, as this is highly configurable.


1For instance, we can have a series of commits C-D-E where the date and time stamp of commit C is in the 1970s, before Git even existed; the date and time stamp of commit D is set far in the future; and the date and time stamp of commit E is "right now". This is not normal and strongly suggests that the date-stamps were faked. But since Git does not depend on them,2 it's harmless.

2Some features in Git speed up use of the commit graph by making assumptions about increasing date stamps. To make this work correctly, some recent Git work now computes a "corrected commit timestamp" internally. For an ordinary commit, the corrected commit timestamp of child C of parent P is max(C.date, P.date+1), more or less. For a root commit we simply use the date stamp as-is and for a multi-parent commit we find max(P.date ? P ∈ parents) and add 1 and use that as the other input to our outer max function.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...