Search code examples
gitbitbucketgit-merge

fast forward merge of outdated master


I have an outdated master branch which was updated back in 2020.

Now I want to sync my master branch with latest release branch, I tried below

git clone https://repo...
cd db-repo-1
git checkout release
git checkout master
git merge release

Here merge happens with fast-forward method and 1000+ files got changed/added.

Since here merged happened with fast-forward method, can I be sure that all the code present in the release branch is now in master too (master does not have anything extra and is exactly same as release) or there could be any scenarios where my master is still not in sync with release?

Note: I want all code from release to master as release has the latest code and trying to avoid re-write history option.


Solution

  • A fast-forward merge is simply a case where the head commit of the current branch is an ancestor of the head commit of the other branch. In this scenario, there is no need to create a merge commit between the two branches, because there aren't two different lines of development to combine, but just a single one, where one ref moved forward (the other branch), while the other one "stayed behind" (the current branch). Git resolves fast-forward merges by simply assigning to the ref of the current branch the commit pointed by the other branch (i.e. its head commit).

    Often the current branch head is an ancestor of the named commit. [...] In this case, a new commit is not needed to store the combined history; instead, the HEAD (along with the index) is updated to point at the named commit, without creating an extra merge commit.

    So, to answer your question, if a merge is resolved as a fast-forward merge, you can be sure that there is no data loss, as both branches are pointing to the exact same history of commits.


    As a side note, a branch is just a ref, and it's implemented as a file containing the SHA1 of its head commit. It's really not that special. You can check that by simply opening with an editor any branch file contained in refs/heads, you will see the SHA1 of the branch's head commit. The whole heavy lifting is actually done via the commit DAG (the directed acyclic graph).