当 Dan 将文本更改为“aB”时会发生什么?和约翰到“abc”?

发布于 2024-09-06 05:14:09 字数 191 浏览 3 评论 0原文

想象一个非常简单的文本文档(text.txt),其内容只是字母“ab”。该文件已签入规范(远程)存储库。两个人对该存储库和该文件进行了本地关闭,并开始编辑它。 Dan 将内容更改为“aB”(注意大写 B),John 将其版本编辑为“abc”。 Dan 进行提交并将其推送到规范存储库。稍后约翰会进行本地提交并将更改推送到远程。当约翰推送他的存储库时会发生什么(消息)?

Imagine a very simple textdocument (text.txt) with as content just the letters 'ab'. This file has been check-in in a canonical (remote) repository. Two people have a local close of this repository and thus this file and start editing it. Dan changes the content to 'aB' (note the capital B) and John edits his version to 'abc'. Dan does a commit and pushes it to the canonical repository. John a little bit later does a local-commit and pushes the changes to remote. What happens (message) when John pushes his repository?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆梦 2024-09-13 05:14:09

这取决于约翰在推动时使用的标志。

默认情况下,它将无法推送,因为远程分支头(Dan 的提交)不是 John 修订的祖先。

使用 -f--force,它会简单地用 John 的更改覆盖 Dan 的更改,从而有效地撤消 Dan 的推送 - 如果服务器至少设置为允许强制推送。许多 git 服务器会简单地拒绝这样做。

一般来说,“正确”的方法是约翰尝试正常地推动。他会看到我提到的错误,并知道其他人已经进行了更改。然后他将执行 git pull 来检索 Dan 的更改并将其与他自己的更改合并。拉取将尝试合并,导致文本文件发生冲突,并将其留给 John 修复。 John 解决冲突后(也许通过使文件包含“aBc”,然后使用 git add text.txt; git commit 让 git 知道),他的本地存储库将包含一个“合并提交”被标记为包括这两个更改。然后他可以将其推送到服务器,而不会出现其他问题。

It depends on what flags John uses when he pushes.

By default, it will fail to push, because the remote branch head (Dan's commit) is not an ancestor of John's revision.

With -f or --force, it will simply overwrite Dan's change with John's, effectively undoing Dan's push -- if the server is set to allow forced pushes at least. Many git servers will simply refuse to do this.

Generally, the 'right' way to do it is for John to try to push normally. He will see the error I mention, and know that someone else has made changes. Then he will do a git pull to retrieve Dan's changes and merge them with his own. The pull will attempt the merge, result in a conflict on your text file, and leave it for John to fix. After John resolves the conflict (perhaps by making the file contain 'aBc' and then using git add text.txt; git commit to let git know), his local repository will include a 'merge commit' that is marked as including both changes. He can then push that to the server without further issues.

奶气 2024-09-13 05:14:09

不存在冲突。约翰的推送将被拒绝,因为他尝试推送的提交不是远程分支的直接后代。

如果 John 希望推送他的提交,他必须首先将其与远程分支头部的提交合并,或者在该提交之上回扣他的提交。此时,他必须选择如何解决文本文件中产生的冲突。

There is no conflict. John's push will simply be refused because the commit which he is trying to push is not a direct descendant of the remote branch.

If John wants his commit to be pushed he must first either merge it with the commit that is the head of the remote branch or rebate his commit on top of that commit. At this point he will have to choose how to resolve the resulting conflict in the text file.

无法回应 2024-09-13 05:14:09

会有合并冲突

There will be a merge conflict

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文