简体   繁体   中英

Backup then reset master branch with git?

I have a git repository (on github) that has the first state of a project which was started then abandoned by its first developer.

We are some to have decided to take back this project, but we agreed not to start from the previous code, because it does not match exactly what we plan to do and was not so developed.

So it's a start from scratch, but I would like to keep a track of what as been done by our predecessor, so we can refer to it if needed. The ideal would be to have a git repository with our master branch we are working on currently, and a old-dev branch, split from master at the initial commit, tracking the old version of master .

After reading these pages ( renaming your master branch and how to create an empty branch ), I tried to use git branch --orphan new-dev to create a new branch and replace master with this one after having moved it to old-dev using git branch -m master old-dev . But then git behaves strangely, making an initial commit copying old master and then having me removing everything.

How can I do what I'm trying cleanly, to have a master branch totally clean of old stuff ? Maybe by creating a new repository and importing the old one ? Or are there so tools one github that can help me ? I'm not sure how to proceed...

As mention in " In git, is there a simple way of introducing an unrelated branch to a repository? ", git checkout --orphan "doesn't do exactly what the asker wanted, because it populates the index and the working tree from <start_point> (since this is, after all, a checkout command)"

So a cleaner solution would be to create your new master branch in a new git repo , and then import that branch in your current repo (where master was renamed, and where there is not a master branch yet)

$ cd /path/to/repo
$ git fetch /path/to/unrelated master:master

That way, your master branch starts from a clean history.

git checkout old_master -b
git checkout master
rm [all the old directories and files but not .git mind you]
git add -u .
gir commit -m "Brave new world"

You will now have the old code in the branch old_master and a clean directory.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM