2010-08-20 5 views
0

나는 git에서 분기하는 것을 처음 접했고 조금은 swithing 지점에서의 행동에 혼란 스럽다. 다음 단계를 따르십시오 :왜 지점을 전환 할 때 git merge가 자동으로 변경됩니까?

git init 
Initialized empty Git repository in /Users/mads/Desktop/testing/.git/ 

echo 'hello a' > a.txt 
echo 'hello b' > b.txt 
git add *.txt 
git commit -m "Initial commit" 
[master (root-commit) 1ab870f] Initial commit 
2 files changed, 2 insertions(+), 0 deletions(-) 
create mode 100644 a.txt 
create mode 100644 b.txt 

git status 
# On branch master 
nothing to commit (working directory clean) 

git branch new_feature 
git checkout new_feature 
Switched to branch 'new_feature' 

ls 
a.txt b.txt 

echo "hello c" > c.txt 
git add c.txt 

echo "hello a, new version" > a.txt 

git status 
# On branch new_feature 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# new file: c.txt 
# 
# Changed but not updated: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: a.txt 
# 

git commit -m "Added new feature" 

[new_feature 1ccda31] Added new feature 
1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 c.txt 

git checkout master 
M a.txt 
Switched to branch 'master' 

cat a.txt 
hello a, new version 

체크 아웃시 a.txt의 변경 사항이 자동으로 마스터로 가져 오게되는 이유는 무엇입니까? 이것이 '합병'의 목적이 아닌가? 나는 지점에서 일한 다음 다른 것으로 전환하는 것이 분리 될 것이라고 생각했습니다.

답변

6

수정 한 후에는 결코 git add a.txt을 실행하지 않았습니다. 힘내는 파일에 대한 변경 사항을 자동으로 추적하지 않습니다. 이미 저장소에 추가 한 파일에도 적용됩니다. (이것은 SVN과 다릅니다.) 예를 들어, 변경된 파일을 변경하고자 할 때, 파일을 변경할 때마다 명시 적으로 git add의 파일을 써야합니다.

-a 옵션을 git commit에 사용할 수 있습니다.이 옵션은 이미 추적중인 파일에 대한 변경 사항을 자동으로 추가하고 커밋합니다. 따라서 svn commit에 가장 가까운 것은 git commit -a입니다.

3

커밋에 a.txt을 추가하지 않았으므로 여전히 수정 된 작업 파일입니다. 체크 아웃 마스터에서는 변경 내용을 덮어 쓰지 않으므로 a.txt의 변경 사항이 작업 디렉토리에 남아 있습니다.

2

문제는 커밋되지 않은 것입니다.

그 이유는 M a.txt은 마스터를 다시 체크 아웃했기 때문입니다.

커밋이 아닌 커밋 -a을 수행하면 변경된 모든 파일이 커밋됩니다. 또는 커밋 할 변경된 파일을 모두 추가해야합니다.

모든 것이 올바르게 커밋되면 분기가 잘 분리되어 있음을 알 수 있습니다.

관련 문제