2012-09-16 5 views
2

git add -p을 사용하여 코드 변경 사항을 여러 커밋으로 분할했습니다. 그러나 그 후 git commit을 수행하면 커밋되지 않은 것들을 포함하여 모두 변경됩니다. 나는 SO에 관한 몇 가지 질문을 보았지만 명백한 실수는 발견 할 수 없었다. 내가 뭘 잘못하고 있는지 이해할 수있게 도와 주실 수 있겠습니까? 아래는 제가 시도한 명령과 그 결과입니다.git commit은 unstaged hunks를 커밋합니다.

bash-3.2$ git diff test11.txt 
diff --git a/test11.txt b/test11.txt 
index f077274..e811cae 100644 
--- a/test11.txt 
+++ b/test11.txt 
@@ -1,5 +1,5 @@ 
-Hello 
-World 
+hello 
+world 

-Blahblahblah 
-blah 
+blahblahblah 
+Blah 
bash-3.2$ git add -p test11.txt 
diff --git a/test11.txt b/test11.txt 
index f077274..e811cae 100644 
--- a/test11.txt 
+++ b/test11.txt 
@@ -1,5 +1,5 @@ 
-Hello 
-World 
+hello 
+world 

-Blahblahblah 
-blah 
+blahblahblah 
+Blah 
Stage this hunk [y,n,q,a,d,/,s,e,?]? s 
Split into 2 hunks. 
@@ -1,3 +1,3 @@ 
-Hello 
-World 
+hello 
+world 

Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y 
@@ -3,3 +3,3 @@ 

-Blahblahblah 
-blah 
+blahblahblah 
+Blah 
Stage this hunk [y,n,q,a,d,/,K,g,e,?]? n 

bash-3.2$ git status 
# On branch test 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
#  modified: test11.txt 
# 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
#  modified: test11.txt 
bash-3.2$ git commit test11.txt 
[test 1b85189] Test12 
1 files changed, 4 insertions(+), 4 deletions(-) 
bash-3.2$ git status 
# On branch test 
nothing added to commit 

답변

10

git commit 명령에 파일 이름을 지정하지 마십시오.

기본적으로 다른 매개 변수가없는 git commit은 색인의 내용을 커밋합니다 (사용자가 git add을 통해 준비한 항목).

그러나 파일 이름을 지정하면 (예 : git commit <filename>) Git은 실제로 색인을 완전히 무시하고 작업 디렉토리에있는 지정된 파일의 현재 상태를 커밋합니다.


기본적으로, 하나 git add또는git commit와 파일 이름을 지정 사용하지만, 둘 다 할 수 없습니다. 대신 쓰기 git commit <file>

+0

감사를 기록 할 수 있습니다. 이것은 내 문제를 해결하는 데 도움이됩니다. 내가 여러 파일을 상연했기 때문에이 방법을 시도했지만, 모든 파일을 한 번에 커밋하고 싶지 않았기 때문에이 방법을 시도했습니다. 이 경우에는 파일을 한 번에 하나씩 추가/커밋하는 것이 가장 좋습니다. –

+1

예, 기본적으로 준비 영역을 사용하여 커밋 내용을 구성한 다음 준비된 내용을 커밋합니다. 린스하고 반복하십시오. – Amber

2
$ man git-commit 
NAME 
     git-commit - Record changes to the repository 

SYNOPSIS 
     git commit [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run] 
        [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>] 
        [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify] 
        [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>] 
        [--status | --no-status] [-i | -o] [--] [<file>...] 
[...] 

     <file>... 
      When files are given on the command line, the command commits the contents of the named files, without recording the changes already 
      staged. The contents of these files are also staged for the next commit on top of what have been staged before. 

, 당신은 당신의 대답 단지 git commit 또는 git commit -m "this is my commit message"

+0

답변 해 주셔서 감사합니다. 도움이되었습니다. 불행히도, 나는 이것을 골라야하기 때문에이 대답을 받아 들일 수 없었다. –

관련 문제