我是git分支的新手。我想做的是一个新功能,保留原始的母版,以防我需要返回并从那里做其他事情。
为此,我做了如下操作:
git branch new feature
git checkout newfeature
从newfeature
分支,我做了相当多的更改(我修改了78个文件)。下面是git状态的摘要:
On branch newfeature
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: //a long list of 60 files
Untracked files:
(use "git add <file>..." to include in what will be committed)
// a long list of 18 files
no changes added to commit (use "git add" and/or "git commit -a")
我没想到的是,当我用git checkout master
命令回到master
时,我看到所有的变化,就好像我在新功能分支中一样。下面是master的git状态总结:
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: //a long list of 60 files
Untracked files:
(use "git add <file>..." to include in what will be committed)
// a long list of 18 files
no changes added to commit (use "git add" and/or "git commit -a")
我如何在原始母版(不应该有更改)和新特性(包含对所有78个文件的更改)之间切换?
我如何在原始母版(不应该有更改)和新功能(包含对所有78个文件的更改)之间切换?
Git关于提交。分支是一个提交。你需要做一个commit。
在newfeature
分支上说
git add .
git commit -m 'your message here'
现在newfeature
是一个提交包含这些文件的更改版本。所以改成master
commit…
git switch master
…并返回newfeature
commit…
git switch newfeature
…将如你所愿轮流。