Git은 일부 파일에서 변경 사항을 취소합니다.
- Git에서 한 파일의 작업 사본 수정을 취소 하시겠습니까? 답변 13 개
코딩하는 동안 진행 상황을 추적하기 위해 인쇄 문을 일부 파일에 추가했습니다.완료되면 일부 파일의 변경 사항을 되돌릴 수 있지만 실제로 작업 한 파일을 커밋 할 수 있습니까? 파일에 인쇄를 추가
A
했지만 파일을 수정 했다고 가정 해보십시오
B
.
B
내가 커밋하고
A
싶은 것입니다. 그리고 이전 상태로 돌아가고 싶습니다.
파일 A에 대한 변경으로 수행 한 작업에 따라이를 수행하는 세 가지 기본 방법이 있습니다. 아직 색인에 변경 사항을 추가하지 않았거나 커미트 한 경우 checkout 명령을 사용하려고합니다. 저장소와 일치하는 작업 사본의 상태 :
git checkout A
색인에 이미 추가 한 경우 reset을 사용하십시오.
git reset A
커밋 한 경우 revert 명령을 사용합니다.
# the -n means, do not commit the revert yet
git revert -n <sha1>
# now make sure we are just going to commit the revert to A
git reset B
git commit
반면에 커밋을했지만 커밋에 되돌리고 싶지 않은 파일이 많이 포함 된 경우 위의 방법에는 "리셋 B"명령이 많이 포함될 수 있습니다. 이 경우이 방법을 사용할 수 있습니다.
# revert, but do not commit yet
git revert -n <sha1>
# clean all the changes from the index
git reset
# now just add A
git add A
git commit
또 다른 방법은 rebase -i 명령을 사용해야합니다. 이것은 하나 이상의 편집 커밋이있는 경우 유용 할 수 있습니다.
# use rebase -i to cherry pick the commit you want to edit
# specify the sha1 of the commit before the one you want to edit
# you get an editor with a file and a bunch of lines starting with "pick"
# change the one(s) you want to edit to "edit" and then save the file
git rebase -i <sha1>
# now you enter a loop, for each commit you set as "edit", you get to basically redo that commit from scratch
# assume we just picked the one commit with the erroneous A commit
git reset A
git commit --amend
# go back to the start of the loop
git rebase --continue
출처 :
http://git-scm.com/book/en/Git-Basics-Undoing-Things
git checkout-modifiedfile.java
1) $ 자식 상태 수정 된 파일을 볼 수 있습니다2) $ git checkout-modifiedfile.java3) $ git 상태
git add B # Add it to the index
git reset A # Remove it from the index
git commit # Commit the index
:
git checkout A
예;
git commit FILE
FILE 만 커밋합니다. 그런 다음 사용할 수 있습니다
git reset --hard
다른 파일에서 로컬 변경 사항을 취소합니다.
There may be other ways too that I don't know about...
edit: or, as NicDumZ said, git-checkout just the files you want to undo the changes on (the best solution depends on wether there are more files to commit or more files to undo :-)
Why can't you simply mark what changes you want to have in a commit using "git add <file>" (or even "git add --interactive", or "git gui" which has option for interactive comitting), and then use "git commit" instead of "git commit -a"?
In your situation (for your example) it would be:
prompt> git add B
prompt> git commit
Only changes to file B would be comitted, and file A would be left "dirty", i.e. with those print statements in the working area version. When you want to remove those print statements, it would be enought to use
prompt> git reset A
or
prompt> git checkout HEAD -- A
to revert to comitted version (version from HEAD, i.e. "git show HEAD:A" version).
참고URL : https://stackoverflow.com/questions/933329/git-undo-changes-in-some-files
'programing' 카테고리의 다른 글
numpy 배열을 이미지로 변환하고 표시하는 방법은 무엇입니까? (0) | 2020.05.17 |
---|---|
익명 유형 결과를 반환 하시겠습니까? (0) | 2020.05.16 |
탭을 재배치하는 vim 명령이 있습니까? (0) | 2020.05.16 |
nginx-client_max_body_size는 영향을 미치지 않습니다 (0) | 2020.05.16 |
파이썬으로 마우스 제어 (0) | 2020.05.15 |