Program Tip

“git commit”과“git push”의 차이점은 무엇입니까?

programtip 2020. 9. 28. 09:53
반응형

“git commit”과“git push”의 차이점은 무엇입니까?


제가 살펴볼 Git 튜토리얼 git commit에서는 변경 사항을 저장하는 데 사용됩니다.

그렇다면 무엇을 git push위해 사용됩니까?


기본적으로 git commit" 저장소에 변경 사항을 기록 하는 반면 git push" " 관련 객체와 함께 원격 참조를 업데이트합니다 . 따라서 첫 번째는 로컬 저장소와 연결하여 사용되는 반면 후자는 원격 저장소와 상호 작용하는 데 사용됩니다.

다음은 git 모델과 명령을 설명하는 Oliver Steele 의 멋진 사진입니다 .

Git 데이터 전송 명령

에 대한 자세한 읽기 git pushgit pullGitReady.com (내가 처음에 언급 된 기사)


commit : 로컬 저장소에 변경 사항 추가

push : 마지막 커밋을 원격 서버로 전송


글쎄, 기본적으로 git commit은 변경 사항을 로컬 저장소에 저장하고 git push는 변경 사항을 원격 위치로 보냅니다.


git은 분산 버전 제어 시스템이므로 커밋은 로컬 저장소에 변경 사항을 커밋하는 반면 푸시는 원격 저장소에 변경 사항을 푸시한다는 점이 다릅니다.


git push로컬 저장소에서 수행 한 커밋을 원격 저장소에 추가하는 데 사용됩니다.와 함께 git pull사람들이 공동 작업 할 수 있습니다.


커밋 : 스냅 샷 | 체인지 셋 | 역사 _ 기록 | 버전 | 저장소의 '다른 이름으로 저장' . Git 저장소 = 커밋 시리즈 (트리) .

로컬 저장소 : 컴퓨터의 저장소.

원격 저장소 : 서버의 저장소 ( Github ).

git commit: 로컬 저장소에 커밋 (마지막 커밋 + 단계적 수정)을 추가 합니다. (모든 커밋은에 저장됩니다 )/.git

git push, git pull: 로컬 저장소를 관련 원격 저장소 동기화 합니다. push-에서 변경 사항을 적용 지역원격 , pull-에서 변경 사항을 적용 원격 으로 지역 .


git commit변경 사항을 로컬 저장소에 기록 합니다.

git push 로컬 변경 사항으로 원격 저장소를 업데이트 하십시오 .


주의해야 할 세 가지 사항 :

1) 작업 디렉토리 ----- 코드 파일이있는 폴더

2) 로컬 저장소 ------ 이것은 우리 시스템 내부에 있습니다. COMMIT 명령을 처음 만들 때이 Local Repository가 생성됩니다. 작업 디렉토리가있는 동일한 위치에
Checkit (.git) 파일이 생성됩니다.
그 후 commit 할 때마다 Working Directory의 파일에서 변경 한 내용이 로컬 저장소 (.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


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.

The git push command takes two arguments:

A remote name, for example, origin A branch name, for example, master

For example:

git push  <REMOTENAME> <BRANCHNAME> 
git push  origin       master

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.

Please don't take this analogy out of this context -- committing and pushing are nothing like saving an edited file and copying it. That said, it should hold for comparisons sake only.


git commit is nothing but saving our changes officially, for every commit we give commit message, once we are done with commits we can push it to remote to see our change globally

which means we can do numerous commits before we push to remote (we can see the list of commits happened and the messages too) git saves each commit with commit id which is a 40 digit code

and I use git push only when i wanted to see my change in remote (There after i will check whether my code worked in jenkins)


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.


Push: Push the branch to remote, along with necessary commits and objects. Creates named branch in the remote repo if it doesn’t exist.

Commit: Record your changes to the local repository, Commit the staged snapshot. It keeps track of the changes made between each commit.

When you commit your changes, you save the changes as a single logical set in your local repository. You can do this multiple times without pushing. Until they are pushed, they do not leave your local repository meaning the remote repository won't have these sets of changes yet, so when other people pull from the remote repository, your commits won't be pulled.

When you push, all the commits you made in your local repository will be transferred to the remote repository, so when other developers who share this remote repository pull, they will have your changes transferred to their local repositories.


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


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


git commit is to commit the files that is staged in the local repo. git push is to fast-forward merge the master branch of local side with the remote master branch. But the merge won't always success. If rejection appears, you have to pull so that you can make a successful git push.

참고 URL : https://stackoverflow.com/questions/2745076/what-are-the-differences-between-git-commit-and-git-push

반응형