首先,您滥用了 Git 术语。 Aref or 参考只是一个名称,例如refs/heads/master
(分支全名-名称master
) or refs/tags/v1.2
(标签的全名v1.2
).
Next: git push
不推files. What git push
发送的是:
- 根据需要提交和/或带注释的标签以及所有其他必需的对象;
- 一系列参考更新请求(默认)或命令(
--force
).
It's up to the receiving server to decide whether to obey these requests or commands. The default for a request to update a branch name—a reference within the refs/heads/
namespace—is to obey a polite request if and only if it is a fast-forward operation, and to obey any command (any forced update). Files are completely irrelevant here. A branch name update is a fast-forward operation if and only if the new commit hash ID has the old commit hash ID as an ancestor.1
要推送单个引用,只需执行以下操作:
git push <remote> <local-name>:<remote-name>
要推送多个,只需执行以下操作:
git push <remote> <l1>:<r1> <l2>:<r2> ... <ln>:<rn>
(省略冒号后面的名称git push
意味着其他 Git 应该使用与您在本地 Git 中使用的名称相同的名称。)
任何提交附带的文件都是提交快照中的文件。因为你只能推commits(不是文件),无法推送文件。
(当然,你可以使用一些东西other与 Git 相比,将文件发送到服务器,并让服务器就地更新文件。但在这种情况下根本不需要询问 Git!)
1Git maintains a Directed Acyclic Graph or DAG of commits (and in fact all objects, but commits are the ones of interest here). The result of a push is a change to the DAG. If the change is a pure addition, no commits will be lost. Such an update is by definition a fast-forward and hence allowed. If the change results in some commits becoming unreachable from the updated reference, the change is by definition a non-fast-forward and hence polite-request updates are refused by default.
非快进更新是否实际上丢失提交取决于这些提交是否可以通过其他外部名称访问。这更难计算——并非不可能,只是通过查看正在更新的一个参考并不能立即明显看出。因此,默认情况下需要快进更新的设计原则。
简而言之,Git 确实在做graph https://xkcd.com/1597/ theory http://think-like-a-git.net/sections/git-makes-more-sense-when-you-understand-x/example-3-homeomorphic-endofunctors.html.