Mr_and_Mrs_D
Mr_and_Mrs_D

Reputation: 34036

Is there a way to backup a branch in git and be able to "reimport" it?

I have a branch I want to delete but possibly be able to restore it with full history -is there a way to do this ? So want this:

a - b - c - d - e    master
     \
      f - g    tmp

to become:

a - b - c - d - e

and have a - b - f - g stored somehow that I can reapply it - is it possible ?

Upvotes: 4

Views: 5926

Answers (3)

M.M
M.M

Reputation: 141628

Perhaps you could use git fast-export to save the branch to a file. Then if you need it later you can use git fast-import to get it back.

To accomplish saving the single branch tmp (that is, commits f and g), you could use the triple dot syntax, as follows:

git fast-export master...tmp

Upvotes: 5

Christoph
Christoph

Reputation: 28075

Just clone the repository to another location and then delete the branch from the original repository. You will be able to examine it in the cone and if needed pull it back in from there.

A branch in a clone is basically nothing more than a branch that lives somewhere distinct from your current repository. You can always move the branch back to your old repository at a later point.

It's even easier to push back the branch to your original repository from your clone.

So, in your clone just do:

git push origin that_branch 

Ever pushed a branch to github? Yep, that's exactly the same thing.

Upvotes: 1

Makoto
Makoto

Reputation: 106470

It seems that you've already got what you want in order to preserve the changes of tmp. You should keep the branch around until it no longer makes sense to in order to apply the changes from tmp into master.

That can be accomplished with something as simple as:

git checkout master
git merge tmp

This will apply your changes from tmp onto master.

If you were to back up your git history to some other server or somewhere else, you'd be doing pretty much the same thing; the history graph would still appear the same, and you'd be resurrecting the changes in the same fashion.

Upvotes: 0

Related Questions