gpt4 book ai didi

Git checkout 不提交

转载 作者:行者123 更新时间:2023-12-05 05:24:50 24 4
gpt4 key购买 nike

checkout 前是否需要提交到 git 存储库?我听说是这样,因为我可能会丢失更改。然而,在修改文件并 checkout 后,我可以很容易地返回到我以前的分支并且我没有丢失任何工作。该文件的状态为 M。

他们说 here M 表示已 merge (这很奇怪,我认为它会通知我有关修改的信息)。

$ git checkout master
M README
Switched to branch 'master'
$ cat README
This is the README file.
This line was added in the working directory while in the test branch.

来自“不提交 Git Checkout:没有冲突”部分。M README 是什么意思?

感谢您的帮助。

最佳答案

git checkout 将不会处理是否可以删除任何当前修改。

https://git-scm.com/book/en/v2/book/01-introduction/images/areas.png

(图片来自“Getting Started - Git Basics”)

example mentioned实际使用 git checkout -m (并且没有提交),这意味着修改被 merge :

-m
--merge

When switching branches, if you have local modifications to one or more files that are different between the current branch and the branch to which you are switching, the command refuses to switch branches in order to preserve your modifications in context.

However, with this option, a three-way merge between the current branch, your working tree contents, and the new branch is done, and you will be on the new branch.

最好在 checkout 之前提交(或 stash )当前更改,但 checkout -m 至少可以 merge 这些更改而不是失败(或在 checkout 时删除它们-f(另见“What's the difference between “git reset” and “git checkout”?”)。

What does M README mean

那是未暂存(和未提交)的修改,进行中的工作。
git checkout -m 允许将该修改 merge 到目标分支中,而不是使简单的 git checkout 失败。
另请参见“What’s In The Index? What’s Changed?”。

https://git-scm.com/figures/18333fig0201-tn.png

关于Git checkout 不提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33223440/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com