简体   繁体   English

Git侧分支覆盖了主分支?

[英]Git side branch overrode main branch?

I am not sure if I am using Git incorrectly, but I have a main branch.我不确定我是否错误地使用了 Git,但我有一个主分支。 I wanted to test a new feature so I created a side branch.我想测试一个新功能,所以我创建了一个分支。 I ran我跑了

git branch new-feature
git checkout new-feature

Then, I modified my code in the new-feature branch.然后,我在new-feature分支中修改了我的代码。 I realized this new feature wasn't very good, so I decided to switch back to my main branch and delete the new-feature branch.我意识到这个新功能不是很好,所以我决定切换回我的主分支并删除new-feature分支。

I ran a git checkout main .我跑了一个git checkout main However, my code did not update back to what it was before.但是,我的代码并没有更新回原来的样子。 Additionally, all the modules I modified now has an M beside them.此外,我修改的所有模块现在旁边都有一个M I am wondering how I can restore my main branch.我想知道如何恢复我的主分支。

Specifically, when I checkout the main branch, I get:具体来说,当我检查主分支时,我得到:

Switched to branch 'main'
M        Module1.txt
M        Module2.txt...

You are using Git correctly.您正在正确使用 Git。

  1. You created (and switched to) a new branch.您创建(并切换到)一个新分支。
  2. You modified some files.您修改了一些文件。
  3. You did not commit the changes .没有提交更改 That means those changes aren't on any branch.这意味着这些更改不在任何分支上。
  4. When you switched back to the main branch, git didn't discard those changes because they didn't belong to any branch.当您切换回main分支时,git 并没有丢弃这些更改,因为它们不属于任何分支。

The files show up as modified (that's what the M means) because they still contain your changes.这些文件显示为已修改(这就是M的意思),因为它们仍然包含您的更改。 If you want to discard those changes:如果您想放弃这些更改:

git checkout Module1.txt Module2.txt

This will replace the files with the current version from the main branch.这将用main分支中的当前版本替换文件。

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

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