git - 在 pull 之前提交所有内容,为什么?

标签 git git-pull git-commit

在分支机构工作时,我会更改一些文件。我的一位同事告诉我,他 push 了一项更改,我应该取消该更改以解决眼前的问题。如果我不提交更改,git 不会让我 pull 。即使我修改的所有文件都没有更新。

我想知道为什么会这样,如果可能的话,有没有办法避免这种情况?

最佳答案

git pull 本质上是一个获取,然后是一个 merge 。 merge 通常要求工作目录处于干净状态;他们这样做是为了您的安全:

Warning: Running git merge with uncommitted changes is discouraged: while possible, it leaves you in a state that is hard to back out of in the case of a conflict. (source)

和:

If any of the remote changes overlap with local uncommitted changes, the merge will be automatically cancelled and the work tree untouched. It is generally best to get any local changes in working order before pulling or stash them away with git-stash. (source)

我相信纯 git merge 中的检查实际上比 git pull 中的检查更宽容,因此您可能想尝试先获取然后手动 merge 。但先把东西藏起来总是更好的主意。

关于git - 在 pull 之前提交所有内容,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13767309/

相关文章:

git - 当我提交 Git 时,找不到 cmd.exe

git - 首次提交到 git 存储库时遇到问题

git - 按模式递归添加文件

Git - push.default "matching"和 "simple"有什么区别

repository - 使用 "git commit -a"命令时遇到问题

git - 如何在github中从上游 pull pull 请求

git - 冲突(内容): Merge conflict in

git - 显示自 master 原始分支点以来 git 分支中的所有提交

git - 使用 TortoiseGit 将 SVN Repo 克隆到 Git(包含所有修订版)?

git - 为什么我 pull 的时候需要一直做 `--set-upstream-to`?