0

Whenever I create a new branch (git checkout -b <newBranchName>), I use to get many commit logs:

Merge remote-tracking branch 'upstream/master' into develop    e53c044

Merge remote-tracking branch 'upstream/develop' into develop   feda328

Merge remote-tracking branch 'upstream/develop' into develop   4bbd301

Merge remote-tracking branch 'upstream/develop' into develop   4dfcfcb

Merge remote-tracking branch 'upstream/develop' into develop   bfaccfb

Merge remote-tracking branch 'upstream/develop' into develop   754c0ab

Merge remote-tracking branch 'upstream/develop' into develop   b0454b0

Merge remote-tracking branch 'upstream/develop' into develop   f96182f

Image

How can I create a branch without such logs?

  • Is this question what you asking for? https://stackoverflow.com/questions/1384325/in-git-is-there-a-simple-way-of-introducing-an-unrelated-branch-to-a-repository – tsh Nov 03 '17 at 03:01
  • Not sure what you're asking here, creating a new branch does not introduce any new commits, those commits (whose messages you see) must already be in your repository. Are they on the branch you branched *from*? – Lasse V. Karlsen Nov 03 '17 at 07:46

2 Answers2

0

Maybe orphan parameter of git checkout could help you:

git checkout --orphan NEW_BRANCH

This will create a new branch named NEW_BRANCH with zero commits on it. But now all files stay in cache area, you could use "git rm --cached ..." to unstage:

git rm -r --cached .

-r here could unstage files recursively.

liuwenzhuang
  • 946
  • 7
  • 14
0

The commits for the new created branches are based on the parent branch you created from.

Such as if you create a new branch new from develop branch as below graph:

A---B---C   developer
         \
            new

When you show the logs for new branch, you will find the commits A, B and C are showed.

If you want to create the new branch without showing the parent commits, you can create an orphan branch (execute on develop branch):

git checkout --orphan new

Then there will have no commits on new branch. the commit history will as below:

A---B---C   developer

            new

If you want to create the new branch with only part of the commits for it's parent branch develop, you can use:

git checkout -b new <last commit you want to contain in new branch>

Such as if you want to contain only commits A and B in new branch, you can use the command git checkout -b new <commit id for B>, then the commit history will be:

A---B---C   developer
     \
       new
Marina Liu
  • 36,876
  • 5
  • 61
  • 74