What are the differences between “git commit” and

2019-01-03 00:12发布

In a Git tutorial I'm going through, git commit is used to store the changes you've made.

What is git push used for then?

15条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-03 00:51

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.

Here is a nice picture from Oliver Steele, that explains the git model and the commands:

Git data transport commands

Read more about git push and git pull on GitReady.com (the article I referred to first)

查看更多
迷人小祖宗
3楼-- · 2019-01-03 00:52

in layman terms, git commit is the step before git push you run them in that order to successfully git your file to github.

查看更多
Ridiculous、
4楼-- · 2019-01-03 00:57

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.

查看更多
看我几分像从前
5楼-- · 2019-01-03 00:59

Well, basically git commit puts your changes into your local repo, while git push sends your changes to the remote location.

查看更多
Luminary・发光体
6楼-- · 2019-01-03 01:01

Well, basically git commit puts your changes into your local repo, while git push sends your changes to the remote location. 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

source Google

http://gitref.org/basic/ this link will be very useful too

https://git-scm.com/docs/git-commit

查看更多
我想做一个坏孩纸
7楼-- · 2019-01-03 01:02

It is easier to understand the use of the git commands add and commit if you imagine a log file being maintained in your repository on Github. A typical project's log file for me may look like:

---------------- Day 1 --------------------
Message: Completed Task A
Index of files changed: File1, File2

Message: Completed Task B
Index of files changed: File2, File3
-------------------------------------------

---------------- Day 2 --------------------
Message: Corrected typos
Index of files changed: File3, File1
-------------------------------------------
...
...
...and so on

I usually start my day with a git pull request and end it with a git push request. So everything inside a day's record corresponds to what occurs between them. During each day, there are one or more logical tasks that I complete which require changing a few files. The files edited during that task are listed in an index.

Each of these sub tasks(Task A and Task B here) are individual commits. The git add command adds files to the 'Index of Files Changed' list. This process is also called staging and in reality records changed files and the changes performed. The git commit command records/finalizes the changes and the corresponding index list along with a custom message which may be used for later reference.

Remember that you're still only changing the local copy of your repository and not the one on Github. After this, only when you do a git push do all these recorded changes, along with your index files for each commit, get logged on the main repository(on Github).

As an example, to obtain the second entry in that imaginary log file, I would have done:

git pull
# Make changes to File3 and File4
git add File3 File4
# Verify changes, run tests etc..
git commit -m 'Corrected typos'
git push

In a nutshell, git add and git commit lets you break down a change to the main repository into systematic logical sub-changes. As other answers and comments have pointed out, there are ofcourse many more uses to them. However, this is one of the most common usages and a driving principle behind Git being a multi-stage revision control system unlike other popular ones like Svn.

查看更多
登录 后发表回答