我如何开始一个没有血统的干净的分支,然后逐步提交文件? [英] How can I start a clean branch with no ancestry, then commit files progressively?

查看:83
本文介绍了我如何开始一个没有血统的干净的分支,然后逐步提交文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用GIT进行版本化的PHP框架,我正在计划对其核心进行一些(激烈的)更改。

我想要做的是开始在新分支中开发新内核,但由于此更改可能需要对文件系统进行一些重构,所以我希望尽可能干净地启动这个新分支。



我希望clean分支仅包含核心文件。在完成我的更改时,我希望将框架中的其余模块逐个添加到工作目录,但如果在主服务器上执行更改,请保留合并功能。



我该怎么做?

解决方案

分支无祖先



您需要 - 孤儿标志。例如:

  git checkout master 
git checkout --orphan foo

#Unstage工作树中的所有文件。
git rm --cached $(git ls-files)

会创建一个新分支命名为 foo ,没有祖先,但它会保留当前调用该命令时的任何分支(在本例中为 master 分支)的当前工作树。然后,您可以修改您的工作树以适应,然后进行提交以重新开始该分支的历史记录。



文件的渐进式分段



要对历史记录执行增量式添加,请使用 git add 来仅分阶段执行每次提交所需的文件。 git-add(1)手册页提供了有关添加文件的选择:


可以给出Fileglobs(例如* .c)添加所有匹配的文件。还可以给出一个主要的目录名(例如添加dir / file1和dir / file2的目录)以递归方式添加
目录中的所有文件。



I have a PHP framework versioned with GIT and I'm planning several (drastic) changes to its core.

What I want to do is to start working on the new core in a new branch, but since this change might require some restructuring on the filesystem too, I'd like to start this new branch as cleanly as possible.

I want the clean branch to include only with the core files. As I'm finishing my changes, I want to add the rest of the modules from the framework to the working directory one by one, but keep the ability to merge if I do changes on master.

How can I do that?

解决方案

Branch with No Ancestors

You want the --orphan flag. For example:

git checkout master
git checkout --orphan foo

# Unstage all the files in your working tree.
git rm --cached $(git ls-files)

will create a new branch named foo with no ancestors, but it will preserve the current working tree from whatever branch you were on when you called the command (in this case, the master branch). You can then modify your working tree to suit, and then make a commit to start that branch's history afresh.

Incremental Staging of Files

To perform incremental additions to your history, use git add to stage just the files you want for each commit. The git-add(1) manual page has this to say about adding files selectively:

Fileglobs (e.g. *.c) can be given to add all matching files. Also a leading directory name (e.g. dir to add dir/file1 and dir/file2) can be given to add all files in the directory, recursively.

这篇关于我如何开始一个没有血统的干净的分支,然后逐步提交文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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