Home > Blockchain >  Git create new branch from feature branch without the branch commit history
Git create new branch from feature branch without the branch commit history

Time:08-30

I want to create a new branch based on a feature branch without the commit history of the branch.
It should look like as if I had already pushed the feature branch to the master and create the new branch based on this.

So when I later compare the [master feature branch]-branch with the new branch, it shows only the new added commits from the new branch and not the one from the already pushed feature branch.

I have already tried using the --orphan flag, but this seems to delete all history.

CodePudding user response:

You could:

  • create your new branch from master (or main, the new default branch name)
  • restore your index and working tree with the content from feature branch, and commit

That is:

git switch -c newBranch master
git restore --staged --worktree --source=featureBranch
git commit -m "restore featureBranch content"

CodePudding user response:

(note: perhaps I am missing something)

Simply create a new branch from feature branch :

git checkout -b new-branch feature-branch

If you want to see the commits on new-branch that are not on feature-branch, just run :

git log --graph feature-branch..new-branch

If you are used to a GUI to view the history of your repo, all the GUI clients I have seen offer a way to type feature-branch..new-branch somewhere.

  • Related