Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
453 views
in Technique[技术] by (71.8m points)

git - 将现有未提交的工作移至Git中的新分支(Move existing, uncommitted work to a new branch in Git)

I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch.

(我开始了一项新功能的工作,经过一段时间的编码,我决定该功能应该在其自己的分支上。)

How do I move the existing uncommitted changes to a new branch and reset my current one?

(如何将现有未提交的更改移至新分支并重置当前分支?)

I want to reset my current branch while preserving existing work on the new feature.

(我想重置当前分支,同时保留新功能的现有工作。)

  ask by Dane O'Connor translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the following:

(使用以下内容:)

git checkout -b <new-branch>

This will leave your current branch as is, create and checkout a new branch and keep all your changes.

(这将使您当前的分支保持不变,创建并签出新分支,并保留所有更改。)

You can then make a commit with:

(然后,您可以使用以下命令进行提交:)

git add <files>

and commit to your new branch with:

(并使用以下命令提交到您的新分支:)

git commit -m "<Brief description of this commit>"

The changes in the working directory and changes staged in index do not belong to any branch yet.

(工作目录中的更改和索引中暂存的更改尚不属于任何分支。)

This changes where those changes would end in.

(这将更改这些更改的终止位置。)

You don't reset your original branch, it stays as it is.

(您无需重置原始分支,它会保持原样。)

The last commit on <old-branch> will still be the same.

(<old-branch>上的最后一次提交将保持不变。)

Therefore you checkout -b and then commit.

(因此,您checkout -b然后提交。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...