"git reset"과 "git checkout"의 차이점은 무엇입니까?
난 항상 생각했습니다 git reset
과 git checkout
모두가 특정 커밋을하는 프로젝트 등을 가지고 있다는 점에서, 동일로. 그러나 중복 될 수 있기 때문에 정확히 동일 할 수는 없다고 생각합니다. 이 둘의 실제 차이점은 무엇입니까? svn svn co
은 커밋을 되돌려 야하기 때문에 약간 혼란 스럽습니다 .
추가
VonC과 찰스의 차이점을 설명 git reset
하고 git checkout
정말 잘합니다. 내 현재 이해는 git reset
모든 변경 사항을 특정 커밋으로 되 돌리는 반면 git checkout
지점을 준비하는 것은 다소 있습니다. 다음 두 다이어그램 이이 이해에 매우 유용하다는 것을 알았습니다.
추가 3
에서 http://think-like-a-git.net/sections/rebase-from-the-ground-up/using-git-cherry-pick-to-simulate-git-rebase.html , 체크 아웃 및 재설정 할 수의 에뮬레이션 rebase.
git checkout bar
git reset --hard newbar
git branch -d newbar
git reset
특히 HEAD를 옮기고 인덱스 를 업데이트하는 것에 관한 것 입니다.git checkout
작업 트리 를 업데이트하는 것입니다 (인덱스 또는 지정된 트리로). 분기를 체크 아웃 할 때만 HEAD를 업데이트합니다 (그렇지 않으면 HEAD 가 분리됩니다 ).
(실제로 Git 2.23 Q3 2019에서는git restore
반드시 그런 것은 아닙니다.git checkout
)
이에 비해 svn에는 인덱스가 없기 때문에 작업 트리 만 svn checkout
지정된 개정을 별도의 디렉토리에 복사합니다.
더 가까운 git checkout
것은 :
svn update
(같은 지점에 있다면 같은 SVN URL을 의미)svn switch
(예를 들어 동일한 지점이지만 다른 SVN 저장소 URL에서 체크 아웃 한 경우)
그 모든 세 가지 작업 트리 수정 ( svn checkout
, update
, switch
) 자식에 하나의 명령이 있습니다 git checkout
.
그러나 git에는 인덱스 개념 (리포지토리와 작업 트리 사이의 "스테이징 영역")도 있으므로 git reset
.
Thinkeye 는 주석 에서 " Remy Demystified " 기사를 언급합니다 .
예를 들어, 다른 커밋을 가리키는 '
master
'와 'develop
'의 두 가지 분기 가 있고 현재 'develop
'(HEAD 가 가리킴 )에 있고git reset master
'develop
' 가 실행 되면 ' '자체는 이제 동일한 커밋을 가리 킵니다.master
'않습니다.반면에 우리가 대신 달리면
git checkout master
'develop
'는 움직이지 않을HEAD
것입니다.HEAD
이제 'master
'를 가리 킵니다 .따라서 두 경우 모두
HEAD
commit을 가리 키도록 이동 하고A
있지만 그렇게하는 방법은 매우 다릅니다.reset
분기HEAD
지점을 가리키고, 결제는HEAD
다른 지점을 가리 키도록 이동 합니다.
그러나 그 점에서 :
그러나이 답변의 첫 번째 단락은 오해의 소지가 있습니다. "
git checkout
... 분기를 체크 아웃 한 경우에만 HEAD가 업데이트됩니다 (그렇지 않은 경우 HEAD가 분리됨)".
사실이 아님 :git checkout
브랜치가 아닌 커밋을 체크 아웃하더라도 HEAD를 업데이트합니다 (그렇습니다. 분리 된 HEAD로 끝나지만 여전히 업데이트됩니다).git checkout a839e8f updates HEAD to point to commit a839e8f.
@LarsH가 정확합니다.
두 번째 글 머리 기호는 HEAD가 무엇인지에 대한 오해가 있으므로 지점을 체크 아웃하는 경우에만 HEAD가 업데이트됩니다.
머리는 그림자처럼 당신이 어디에 있든갑니다.
브랜치가 아닌 참조 (예 : 태그) 또는 커밋을 직접 확인하면 HEAD가 이동합니다. 분리 된 헤드는 HEAD에서 분리 된 것이 아니라 헤드가 분기 참조에서 분리 된 것을 의미합니다 (예 :)git log --pretty=format:"%d" -1
.
- 연결된 헤드 상태는로 시작합니다
(HEAD ->
.- detached는 여전히을 표시
(HEAD
하지만 분기 참조에 대한 화살표는 없습니다.
가장 간단한 형태로, reset
작업 트리를 건드리지 않고 인덱스를 재설정하고 인덱스를 건드리지 않고 작업 트리를 checkout
변경합니다.
HEAD
작업 트리를 그대로두면 인덱스가 재설정됩니다 .
git reset
Conceptually, this checks out the index into the working tree. To get it to actually do anything you would have to use -f
to force it to overwrite any local changes. This is a safety feature to make sure that the "no argument" form isn't destructive:
git checkout
Once you start adding parameters it is true that there is some overlap.
checkout
is usually used with a branch, tag or commit. In this case it will reset HEAD
and the index to the given commit as well as performing the checkout of the index into the working tree.
Also, if you supply --hard
to reset
you can ask reset
to overwrite the working tree as well as resetting the index.
If you current have a branch checked out out there is a crucial different between reset
and checkout
when you supply an alternative branch or commit. reset
will change the current branch to point at the selected commit whereas checkout
will leave the current branch alone but will checkout the supplied branch or commit instead.
Other forms of reset
and commit
involve supplying paths.
If you supply paths to reset
you cannot supply --hard
and reset
will only change the index version of the supplied paths to the version in the supplied commit (or HEAD
if you don't specify a commit).
If you supply paths to checkout
, like reset
it will update the index version of the supplied paths to match the supplied commit (or HEAD
) but it will always checkout the index version of the supplied paths into the working tree.
One simple use case when reverting change:
1. Use reset if you want to undo staging of a modified file.
2. Use checkout if you want to discard changes to unstaged file/s.
Atlassian give us an excellent explanation about git reset, git checkout and so, git revert. In this article, is explained the different uses of these commands on a different levels - file, staged snapshot and commit.
https://www.atlassian.com/git/tutorials/resetting-checking-out-and-reverting
The key difference in a nutshell is that reset
moves the current branch reference, while checkout
does not (it moves HEAD).
As the Pro Git book explains under Reset Demystified,
The first thing
reset
will do is move what HEAD points to. This isn’t the same as changing HEAD itself (which is whatcheckout
does);reset
moves the branch that HEAD is pointing to. This means if HEAD is set to themaster
branch (i.e. you’re currently on themaster
branch), runninggit reset 9e5e6a4
will start by makingmaster
point to9e5e6a4
. [emphasis added]
See also VonC's answer for a very helpful text and diagram excerpt from the same article, which I won't duplicate here.
물론 어떤 매개 변수가 사용되는지에 따라 인덱스 및 작업 트리에 미치는 영향 checkout
과 영향에 대한 자세한 내용이 reset
있습니다. 두 명령간에 많은 유사점과 차이점이있을 수 있습니다. 그러나 내가 알 수 있듯이 가장 중요한 차이점은 현재 지점의 끝을 움직 일지 여부입니다.
두 명령 (재설정 및 체크 아웃)은 완전히 다릅니다.
checkout X
아니다 reset --hard X
X가 지점 이름이면 checkout X
현재 지점은 변경하지만 변경 reset --hard X
하지는 않습니다.
참고 URL : https://stackoverflow.com/questions/3639342/whats-the-difference-between-git-reset-and-git-checkout
'development' 카테고리의 다른 글
단위 테스트를 수행 할 때 C # "내부"액세스 수정 자 (0) | 2020.02.21 |
---|---|
키 / 값 쌍 파일에서 환경 변수 설정 (0) | 2020.02.21 |
getApplication () 대 getApplicationContext () (0) | 2020.02.21 |
"ON UPDATE CASCADE"를 사용하는 경우 (0) | 2020.02.21 |
파일은 보편적이지만 (세 개의 슬라이스) iOS의 정적 라이브러리에 대한 ARMn7-s 슬라이스 오류가 포함되어 있지 않습니다. (0) | 2020.02.21 |