[英]New to git, why I see my changes on develop branch even if I stage them on feature branch?
I'm new to git.我是 git 的新用户。
I'm following the git-flow branching model so I have the branches master and develop and every time I need a new feature I open a new feature branch.我正在关注 git-flow 分支 model,所以我有分支 master 和 develop ,每次我需要一个新功能时,我都会打开一个新功能分支。
I did some changes to a couple of files in the feature branch and I staged them, not committed yet since the changes are not tested yet:我对功能分支中的几个文件进行了一些更改,并暂存了它们,但尚未提交,因为更改尚未经过测试:
$ git status
On branch feature/ParamConfigFaultCollection
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: IOLSE_User_Objs.h
modified: data.c
Now I need to work on the branch develop, so I switch to it, I use Sourcetree as git GUI and I double click on develop:现在我需要在分支开发上工作,所以我切换到它,我使用 Sourcetree 作为 git GUI,然后双击开发:
and I was expecting that the changes in the stashed files on feature branch would not be visible to develop, but it seems that the changes are present in develop too:我原以为功能分支上隐藏文件的更改对开发不可见,但似乎这些更改也出现在开发中:
$ git status
On branch develop
Your branch is up to date with 'origin/develop'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: IOLSE_User_Objs.h
modified: data.c
What am I doing wrong?我究竟做错了什么?
The changes that you have Staged aren't stashed.您暂存的更改不会被隐藏。 They are prepared for the commit.他们为提交做好了准备。 When switching between branches any uncommitted or not-stashed changes will stay in your working area and when Git can perform the switch to another branch without overwriting your changed files, it will allow you to do so.在分支之间切换时,任何未提交或未隐藏的更改都将保留在您的工作区域中,并且当 Git 可以执行切换到另一个分支而不覆盖您更改的文件时,它将允许您这样做。
If you don't want to take your changes with you, you will have to either:如果您不想随身携带更改,则必须:
Then switch to the other branch.然后切换到另一个分支。
Some clients will offer you to do the stash on your behalf.有些客户会请您代您保管。 I prefer not to do that, since it's easy to forget about the stashed changes when I switch back.我不想那样做,因为当我切换回来时很容易忘记隐藏的更改。
What I'd do instead of stashing, is to commit my changes on the feature branch, preferably with a very clear commit message explaining these aren't ready yet, then, when I come back to that branch I can either:我要做的不是隐藏,而是在功能分支上提交我的更改,最好有一个非常清晰的提交消息来解释这些还没有准备好,然后,当我回到那个分支时,我可以:
git reset --soft HEAD~1
to undo the temporary commit, but keep it's changes, then work some more on it and commit them again later in a new commit.执行git reset --soft HEAD~1
以撤消临时提交,但保留其更改,然后对其进行更多处理并稍后在新提交中再次提交。As long as you don't push your changes to the remote server, you can tweak your local history until it looks the way you want it.只要您不将更改推送到远程服务器,您就可以调整本地历史记录,直到它看起来像您想要的那样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.