Gabriel
Gabriel

Reputation: 42329

Does a new branch named as an old re-named branch inherit its commits?

A few days ago I renamed a branch (following these steps) named emcee in my repo to emcee_old. Then, I created a new branch with the same name (emcee) but branching from a different point in my develop branch. Here's how Github shows this process:

enter image description here

The issue is that now if I check a file in the new emcee branch, it contains a commit that was made to that file in the old emcee. For example the .gitignore file in the new branch shows a commit that was made in 2017 in the old branch:

enter image description here

Even weirder is that if I access the history of that file (in the new branch) that commit is not there:

enter image description here

Why is going on here?

Upvotes: 2

Views: 200

Answers (1)

Kevin Hencke
Kevin Hencke

Reputation: 168

In short, Git does not carry commits between similarly-named branches.

So you created a branch, then renamed it and created a new one by the same name? I have done this in git v1.8.4.2 successfully, though without using Github.

I suspect an problem with Github's interface. You can test this by cutting it out of the loop and studying your repo's history locally, on the command line. Try running git log --graph --all command in a terminal window and study the output. This will display all of your branches, and their converging/diverging history. Also try git log --graph --all .gitignore to limit the history report to the file in question. I expect you will see a more predictable result, different from what Github displays.

This becomes more complex if there are other users of your repository. A collaborator could accidentally restore the old branch during a push. However your link indicates that you don't have to worry about this, as this is a solo effort.

Upvotes: 2

Related Questions