Jwan622
Jwan622

Reputation: 11639

Fast-forwarding and rebase in git

I am reading this and for the most part, I get it. I think I understand rebasing (it obtains a more linear git log history without having to make a commit that is just a three-way commit) I also think I understand the git diagrams. But there are a few words in the paragraph I don't understand.

You’ll notice the phrase “fast-forward” in that merge. Because the commit pointed to by the branch you merged in was directly upstream of the commit you’re on, Git simply moves the pointer forward. To phrase that another way, when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together – this is called a “fast-forward.”

Your change is now in the snapshot of the commit pointed to by the master branch, and you can deploy the fix.

What I don't understand are the terms upstream, pointer, and the last sentence.

In the diagram, why is the red master box above hotfix?

Upvotes: 3

Views: 6772

Answers (1)

Farhad
Farhad

Reputation: 12976

Upstream

One important aspect of git is that it is distributed, and being distributed largely means there are no inherent "upstreams" or "downstreams" in the system. That simply means there is no absolute upstream repo or downstream repo.

Those notions are always relative between two repos and depends on the way data flows:

If "myLocalRepo" has declared "companyRepo" as a remote one, then:

you are pulling from upstream "companyRepo" ("companyRepo" is "upstream from you", and you are "downstream for companyRepo"). you are pushing to upstream ("companyRepo" is still "upstream", where the information now goes back to). Note the "from" and "for": you are not just "downstream", you are "downstream from/for", hence the relative aspect.

Pointer

It has actually the same meaning, as it has in computer programming. A pointer is an indicator for an address in the memory.

In Git world, many implementations are actually modeled and developed with the concept of Pointers.

For instance, the HEAD which is an actual pointer, always points to the last commit on the current branch that you have checked out to. The same applies to tags and reflog results.

In the diagram, why is the red master box above hotfix?

Let's just focus on the explanation for the fast-forward

when you try to merge one commit with a commit that can be reached by following the first commit’s history, Git simplifies things by moving the pointer forward because there is no divergent work to merge together – this is called a “fast-forward.”

The diagram and the explanation is trying to explain that, when you create a new branch, you have all the history of commits of the last branch. Now you continue your work on the new branch, for example making 3 new commits. When merging with the last branch, git does not have to copy all the new branch commit history back. Instead it just has to copy the three new commits and move the HEAD pointer by three commits to have the merge completed. This is called the fast-forwad mechanism.

The master red box contains all the history up to the moment when the new branch of hotfix was created. Now when merge happens, the master and the hotfix, both points to the same commit.

The master red box is actually chronologically older than the hotfix and a reference point for the hotfix branch creation.

Upvotes: 5

Related Questions