简体   繁体   English

GIT分支-本地仓库分支

[英]GIT branching — local repo branch

Let's say I have a project, and a main branch, master. 假设我有一个项目,还有一个主分支master。 Master contains a web solution, and I want to create a new branch, to turn master's solution's css into sass. Master包含一个Web解决方案,我想创建一个新分支,以将Master解决方案的CSS转换为sass。

I create a new branch called scss. 我创建一个名为scss的新分支。

I work off the branch on scss. 我在scss上工作。 Meanwhile, I need to also work on the master branch. 同时,我还需要在master分支上工作。 So I switch between the two. 所以我在两者之间切换。

When I switch from scss to master, Visual Studio asks if I want to update the file that has been changed, I clicked "yes to all". 当我从scss切换到master时,Visual Studio询问是否要更新已更改的文件,我单击了“全部同意”。 And I expect the scss files to disappear from the solution explorer, but they're still there. 我希望scss文件从解决方案资源管理器中消失,但它们仍然存在。 I was wondering if someone can explain to me what's going on locally when I switch branch in the same directory, are the files supposed to actually change? 我想知道有人在我切换同一个目录中的分支时是否可以向我解释本地发生了什么,这些文件是否应该实际更改? Should I have started a different directory with the new branch? 我是否应该使用新分支启动其他目录? What is the right workflow and what should I expect here? 什么是正确的工作流程?在这里我应该期待什么?

While you are developing and your files' changes are not commited on current branch (local or master), the changes you made are not linked to any branch (the commit ID contains the reference of the actual link) so what you are experiencing is the expected behavior. 在开发过程中,文件的更改未提交到当前分支(本地或主分支)时,所做的更改未链接到任何分支(提交ID包含实际链接的引用),因此您正在体验的是预期的行为。 I make use of that when I start working on a task and I realize I am on a different branch so I just switch to the correct branch. 当我开始执行任务时,我会利用这一点,并且意识到自己在不同的分支上,所以我只是切换到正确的分支。

You have 2 solutions from what I see: 1. You stash your changes before switching branch 2. You commit the changes before switching branch 根据我所见,您有2种解决方案:1.在切换分支之前存储更改。2.在切换分支之前提交更改

The stash will be hidden until you apply it back to the correct branch and the commit means the changes were added to a branch. 藏匿处将被隐藏,直到您将其重新应用到正确的分支为止,并且提交意味着所做的更改已添加到分支中。

You can always move between branches till there is no conflict in the modified files . 您始终可以在分支之间移动, 直到修改的文件中没有冲突为止

This featuer is actually required sometimes. 实际上有时需要此功能。 If two branches are having almost same changes, and by mistake/unknowingly you are developing in branch1 but the commit is supposed to go to branch2. 如果两个分支的更改几乎相同,并且由于错误/不知不觉地您正在使用branch1进行开发,但是提交应该转到branch2。 So you can easily checkout the branch and the modified files will be still in *modified state in branch2 branch also, and you can commit here. 因此,您可以轻松检出分支,并且在branch2分支中,修改后的文件仍将处于* modified状态,您可以在此处提交。

If you like to keep the modified changes in branch1 only. 如果您只想将修改后的更改保留在branch1中。 either 要么

  • Commit ( prefer this option, add meaningful commit, saying till what progress you made int that branch.) 提交(首选此选项,添加有意义的提交,直到说出该分支取得了什么进展为止。)
  • Stash

Also if there is any conflict while switching branch, git will throw an error saying 另外,如果在切换分支时有任何冲突,git会抛出错误提示

error: Your local changes to the following files would be overwritten by checkout: [list of files changed in the active branch] Please, commit your changes or stash them before you can switch branches. 错误:检出将覆盖您对以下文件的本地更改:[活动分支中已更改的文件列表]请先提交您的更改或将其存储起来,然后才能切换分支。 Aborting 堕胎

If that changes belongs to the same branch, either commit or stash. 如果该更改属于同一分支,则提交或隐藏。 If not for the other branch, do git stash and switch to the other branch and apply the stash over there. 如果不是另一个分支,请执行git stash并切换到另一个分支,然后在该分支上应用该隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM