为什么我的主人中的代码与我在Visual Studio 2019中的分支机构同时更改?
我仍在尝试了解分支机构的工作方式。我相信,当我基于主分支创建新分支、签出新分支并对其进行更改时,主分支不应更改。但是当我签出 master 时,我在新分支中所做的所有更改也会出现在 Git Changes 的 master 中。我做错了什么?
I'm still trying to understand the way branches work. I believed that when I create a new branch based on the master, checkout the new branch, and make changes in it, that the master should not change. But when I checkout the master, all the changes I've made in the new branch also appear in the master in Git Changes. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改不会自动添加到分支机构,您必须进行上台并进行更改并解释它们的用途。当您切换分支时,不承诺的更改只会跟随您。如果您有更改并切换到主人,则GIT将保留您的未承诺的更改。
“更改”只是您对文件所做的任何未分支和未承诺的更改。 “分阶段更改”是已“分阶段”的未承诺的更改:登台区是您建立下一个提交的地方。
上演后,您将它们提交到当前分支。然后,当您切换到主git时,将签署文件的主版本的清洁副本。
请参阅 Visual Studio 有关Visual Studio和Git的更多信息。阅读 pro git 有关GIT和版本控制的一般概念。
Changes are not automatically added to a branch, you have to stage and commit your changes and explain what they're for. Uncommitted changes will just follow you around as you switch branches. If you have changes and switch to master, Git will retain your uncommitted changes.
"Changes" is just any unstaged and uncommitted changes you have made to your files. "Staged changes" are uncommitted changes which have been "staged": the staging area is where you build your next commit.
Once staged, you commit them to the current branch. Then when you switch to master Git will checkout clean copies of the master versions of the files.
See Make a Git commit in Visual Studio for more about Visual Studio and Git. Read Pro Git for general concepts about Git and version control.
在切换到不同的分支之前,您不会提交更改。在您
添加
并提交
之前,您的更改不会添加到当前分支,因此当您切换分支时它们仍保留在您的文件系统中。有时 git 会告诉您无法切换到不同的分支,因为这样做会破坏您未提交的更改,但如果您要切换到的分支中没有冲突的更改,您通常可以毫无警告地这样做。如果我是对的,您还没有提交更改,那么 master 和您的新分支都不会因您的更改而更改。提交更改会将它们添加到您正在工作的分支中。然后,如果您切换回 master 或其他某个分支,您会发现您所做的更改不存在。
You're not committing your changes before switching to a different branch. Your changes aren't added to the current branch until you
add
andcommit
them, so they remain in your file system when you switch branches. Sometimesgit
will tell you that you can't switch to a different branch because doing so would clobber your uncommitted changes, but if there are no conflicting changes in the branch you want to switch to, you can usually do it with no warning.If I'm right that you haven't committed your changes, then neither master nor your new branch will have been changed by your changes. Committing your changes will add them to the branch you're working in. Then, if you switch back to master or some other branch, you'll see that the changes you made aren't there.