1

I apologize if this is trivial but I've spent the better part of the night searching for a solution and I'm a bit stuck. I've been using Git for version control of a project for which I'm currently the only developer, and after spending a bunch of time working with a given bunch of code, I'd like to start from scratch in my master branch but "archive" all of my previous work in the current master branch and others within my existing repository. I currently have a bunch of commits in the master branch followed by a second series of commits in branch A; it looks something like this:

                 A: C4-C5-C6
                   /
master: C0-C1-C2-C3

I'd like to prepend an empty commit to the project (my current initial commit is not empty), store my current history in a set of branches preserving the hierarchy, and then start working off of that empty commit with new code. That would look something like this:

                     A: C4-C5-C6 
                       /
   oldcode: C0-C1-C2-C3
           /
master: C0' (empty)-C7...

I hope that that makes sense, I get the sense that I'd need to some rebasing but I'm not exactly sure how that would work and I don't want to lose what I already have by accident. Any help would be greatly appreciated, thanks!


EDIT: It just occurred to me that I could potentially just clone copy the current master branch to a new branch to an old branch, commit, and then wipe my working directory in the master branch and commit again. This preserves the actual time-line and my old code, and is probably more "proper". Does that make sense? It would look something like:

                 A: C4-C5-C6
                   /
master: C0-C1-C2-C3-C8(empty)-C9...
                   \
           oldcode: C7

Thanks!

4

2 回答 2

1

Since git 1.7.2, you can use git checkout --orphan <new_branch_name> to create branches that don't share any history with existing branches. This answer has details on how you can use it. So, just rename all your existing branches using git branch -m, then use git checkout --orphan to create the new ones.

于 2013-06-10T04:33:37.033 回答
0

There's probably many ways to do it, but I'd do it like this (based on your diagram):

On your current master branch, do git checkout -b oldcode <-this creates and checks out a new branch named oldcode based of off your current master branch. (So at this very moment since you just created oldcode, it and master will be the same. You can confirm this by running git diff master oldcode)

Next, just go back to your master branch by just doing git checkout master.

Now you can just do any commit on your master branch to make it diverge (be different) from the oldcode branch.

That easy.

You really shouldn't code or "work" on your master branch, that way you avoid having to do this. Or avoid potentially having bugs that make it into your production environment/live code. Branch off the master branch into "topic" branches that you code on and then integrate/git merge your changes back in to master once your're done I... Hope this helps!

于 2013-06-10T04:47:54.670 回答