“git commit”和“git push”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2745076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What are the differences between "git commit" and "git push"?
提问by ben
In a Git tutorial I'm going through, git commit
is used to store the changes you've made.
在我正在学习的 Git 教程中,git commit
用于存储您所做的更改。
What is git push
used for then?
那有什么git push
用呢?
回答by tanascius
Basically git commit
"records changes to the repository" while git push
"updates remote refs along with associated objects". So the first one is used in connection with your local repository, while the latter one is used to interact with a remote repository.
基本上git commit
“记录对存储库的更改”,而git push
“更新远程引用和关联对象”。所以第一个用于与您的本地存储库连接,而后一个用于与远程存储库交互。
Here is a nice picture from Oliver Steele, that explains the git model and the commands:
这是Oliver Steele 的一张漂亮图片,它解释了 git 模型和命令:
Read more about git push
and git pull
on GitReady.com(the article I referred to first)
了解更多关于git push
和git pull
对GitReady.com(我称之为第一的文章)
回答by TheHippo
commit: adding changes to the local repository
commit:向本地存储库添加更改
push: to transfer the last commit(s) to a remote server
push:将最后一次提交传输到远程服务器
回答by markovuksanovic
Well, basically git commit puts your changes into your local repo, while git push sends your changes to the remote location.
好吧,基本上 git commit 将您的更改放入您的本地存储库,而 git push 将您的更改发送到远程位置。
回答by Michael Borgwardt
git push
is used to add commits you have done on the local repository to a remote one - together with git pull
, it allows people to collaborate.
git push
用于将您在本地存储库上所做的提交添加到远程存储库 - 与 一起git pull
,它允许人们进行协作。
回答by Justin Ethier
Since git is a distributed version control system, the difference is that commit will commit changes to your local repository, whereas push will push changes up to a remote repo.
由于 git 是一个分布式版本控制系统,不同之处在于 commit 会将更改提交到您的本地存储库,而 push 会将更改推送到远程存储库。
回答by xged
Commit: Snapshot | Changeset | History_record | Version | 'Save-as'of a repository. Git repository = series (tree) of commits.
提交:快照 | 变更集 | History_record | 版本 | 存储库的“另存为”。Git 存储库 =提交的系列(树)。
Localrepository: repository on your computer.
本地存储库:您计算机上的存储库。
Remoterepository: repository on a server (Github).
远程存储库:服务器上的存储库 ( Github)。
git commit
: Append a new commit(last commit+ stagedmodifications) to the localrepository. (All commits are stored in /.git
)
git commit
:将新提交(上次提交+暂存修改)附加到本地存储库。(所有提交都存储在/.git
)
git push
, git pull
: Sync the localrepository with its associated remoterepository. push
- apply changes from localinto remote, pull
- apply changes from remoteinto local.
git push
, git pull
: 将本地存储库与其关联的 远程存储库同步。push
- 将更改从本地应用到远程,pull
- 将更改从远程应用到本地。
回答by Naresh
git commit
record your changes to the localrepository.
git commit
将您的更改记录到本地存储库。
git push
updatethe remoterepository with your local changes.
git push
更新的远程与本地更改存储库。
回答by Faisal Shaikh
Just want to add the following points:
只想补充以下几点:
Yon can not push until you commit as we use git push
to push commits made on your local branch to a remote repository.
在您提交之前,您无法推送,因为我们git push
习惯于将在本地分支上进行的提交推送到远程存储库。
The git push
command takes two arguments:
该git push
命令有两个参数:
A remote name, for example, origin
A branch name, for example, master
一个远程名称,例如,origin
一个分支名称,例如,master
For example:
例如:
git push <REMOTENAME> <BRANCHNAME>
git push origin master
回答by DEVINDER THAKUR
Three things to note:
需要注意的三件事:
1)Working Directory----- folder where our codes file are present
1)工作目录----- 我们的代码文件所在的文件夹
2)Local Repository------ This is inside our system. When we first time make
COMMIT command then this Local Repository is created.
in the same place where is our Working directory ,
Checkit ( .git ) file get created.
After that when ever we do commit , this will store the
changes we make in the file of Working Directory to
local Repository (.git)
2)本地存储库------这是在我们的系统内部。当我们第一次执行 COMMIT 命令时,就会创建这个本地存储库。在我们的工作目录的同一个地方,
Checkit (.git) 文件被创建。
之后,当我们执行 commit 时,这会将我们在工作目录文件中所做的更改存储到本地存储库 (.git)
3)Remote Repository----- This is situated outside our system like on servers located any where in the world . like github. When we make PUSH command then codes from our local repository get stored to this Remote Repository
3)远程存储库----- 它位于我们系统之外,就像位于世界任何地方的服务器一样。比如github。当我们执行 PUSH 命令时,我们本地存储库中的代码将存储到此远程存储库中
回答by amn
A very crude analogy: if we compare git commit
to saving an edited file, then git push
would be copying that file to another location.
一个非常粗略的类比:如果我们将其git commit
与保存编辑过的文件进行比较,那么git push
就是将该文件复制到另一个位置。
Please don't take this analogy out of this context -- committing and pushing are not quite like saving an edited file and copying it. That said, it should hold for comparisons sake.
请不要将这个类比脱离上下文——提交和推送并不完全像保存编辑过的文件并复制它。也就是说,为了比较,它应该成立。