lakshmen
lakshmen

Reputation: 29094

How to retrieve a branch after finishing a branch in gitflow

I know that when you start for example a feature branch, you type git flow feature start [] and if you want to finish a branch, you type git flow feature finish .

But when you finish a branch, it merges it with develop and deletes the branch automatically.. How do i retrieve that branch?

Upvotes: 3

Views: 1265

Answers (3)

Dahir Warsame
Dahir Warsame

Reputation: 143

The only way to do that is to undo the branch merge.

Here that a look at the accepted anwser => CLICK ME!!!

These steps should do the trick:

Get the sha's needed:

git log

<sha1> is the commit right before the merge
<sha2> is the last commit on develop before you started working on the feature

git checkout develop
git checkout -b feature/<feature-name>
git reset <sha1> --hard
git checkout develop
git reset <sha2> --hard

Push your feature branch.

Upvotes: 0

Roman
Roman

Reputation: 20256

In git branches are really just pointers to commits. Although you can not "retrieve" a branch after it's deleted, you can make a new branch pointing to the same commit as the deleted branch.

One way would be to get the SHA1 of that commit with gitk --all. Then you just execute

 git checkout -b [branch name] [sha1 of your commit] 

Upvotes: 1

Adam Dymitruk
Adam Dymitruk

Reputation: 129744

If you just did that, the feature would be second parent of the current commit (the merge commit). You can recreate the branch with

 git branch my-feature HEAD^2

to create it and check it out in one go

 git checkout -b my-feature HEAD^2

If it's been a while, it's probably not the second parent of the current commit. Use

 gitk 

or

git log --graph --oneline

to find where that branch finished and use the HASH or tree-ish to recreat it. If you guarantee that the merge message is the default one, you can

git branch my-feature $(git log -1 --format=%H --grep="merge branch 'my-feature'")^2

Upvotes: 2

Related Questions