How can I start a clean branch with no ancestry, then commit files progressively?

后端 未结 3 1776
清歌不尽
清歌不尽 2020-12-12 19:22

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 br

3条回答
  •  醉话见心
    2020-12-12 19:41

    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.

提交回复
热议问题