备份然后用git重新设置master分支? [英] Backup then reset master branch with git?

查看:176
本文介绍了备份然后用git重新设置master分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git仓库(在github上),它拥有一个项目的第一个状态,然后由第一个开发者抛弃。

我们有些人有决定收回这个项目,但我们同意不从以前的代码开始,因为它不符合我们打算做的事情,也没有如此发达。



所以这是一个从头开始,但我想跟踪我们的前任所做的事情,所以我们可以在需要时参考它。理想的做法是将git仓库与我们目前正在使用的 master 分支以及 old-dev 分支,在初始提交时从 master 分裂,跟踪旧版本的 master



阅读这些页面(重命名您的主分支如何创建一个空分支),我试着用 git branch --orphan new- dev 创建一个新的分支,并在将它移动到 old-dev 后用这个替换 master $ c>使用 git branch -m master old-dev 。但是, git 的行为很奇怪,首先执行复制旧的 master ,然后让我删除所有内容。



我怎样才能做到干净的工作,让一个 master 分支完全清除旧的东西?
也许通过创建一个新的存储库并导入旧的存储库?还是有工具可以帮助我一个github?我不知道如何继续......

.com / a / 4288660/6309>在git中,是否有一种将不相关分支引入到存储库的简单方法?, git checkout --orphan 并不完全符合提问者的想法,因为它从< start_point> 填充索引和工作树(毕竟,这是一个 checkout command)



所以一个更简洁的解决方案是 在新的git repo中创建新的 master 分支,然后将该分支导入当前repo(其中 master 已重命名,并且没有 master 分支)

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

这样,你的 master 分支从一个干净的历史y。

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重新设置master分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆