2014-06-12 3 views
4

변경 사항을 unstaged했을 때 git pull을 시도하면 실패하거나 커밋 될 수 있습니다. 임시 해결책은 git stash, git pull, git stash pop입니다. 그러나이 작업을 수행 할 다른 방법이 있습니까? unstaged 변경 사항이있는 경우 강제로 git 끌어 오기 싶습니다 경우에만 경우 아래로 가져온 파일을 수정 된 파일을 무시하지 않는? 일명. "derp1", "derp2", "derp3"파일을 가지고 repo를 가지고 있고 "derp1"을 로컬에서 수정하면 git pull은 "derp1"파일을 제외한 모든 것을 덮어 씁니다.무단 변경으로 힘내 당기기

git stash + pull + stash pop이 이미 이것을 달성한다고 가정합니다. 그리고 더 좋은 방법이 있습니까?

하위 모듈에서 발생하는 경우 다른 방식으로 작동한다고 가정합니다.

+0

Stashing은 분명히 내 표준 방법입니다. 만약 내가 어떤 이유로 든 "단지"내 소중한 일을 숨기지 않는다면 그것은 저지를해야 할 때라. 나는 그 일을하기 전에 그것을한다. – Martin

+0

이 질문은 수퍼 유저로 마이그레이션되어 있어야합니다. – DanFromGermany

답변

4

자식의 마지막 버전이

다음 명령을 참조에게 일을 할 것 같다 :

합니다 ([foo]$ 명령이는 foo 디렉토리에 실행 표시하기 전에)

[tmp]$ git --version 
git version 2.0.0 
[tmp]$ git init foo 
Initialized empty Git repository in /tmp/foo/.git/ 
[tmp]$ cd foo 
[foo]$ echo hello > file1 
[foo]$ echo world > file2 
[foo]$ git add . 
[foo]$ git commit -m "first commit" 
[master (root-commit) 5f7d6b3] first commit 
2 files changed, 2 insertions(+) 
create mode 100644 file1 
create mode 100644 file2 
[foo]$ cd .. 
[tmp]$ git clone foo bar 
Cloning into 'bar'... 
done. 

여기에 나는 두 개의 repos를 초기화했습니다 foobar, barfoo

의 클론입니다. 691,363,210

지금 우리가 지금 당기면 비 충돌 변화를

[tmp]$ cd foo 
[foo]$ echo Hello > file1 
[foo]$ git commit -am "correct hello > Hello" 
[master 183c4a5] correct hello > Hello 
1 file changed, 1 insertion(+), 1 deletion(-) 
[foo]$ cd ../bar 
[bar]$ echo "world !" > file2 
[bar]$ git st 
On branch master 
Your branch is up-to-date with 'origin/master'. 

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: file2 

no changes added to commit (use "git add" and/or "git commit -a") 

을 시뮬레이션 할 수 있습니다, 모든 충돌의 변화 (우리는 바는 포함에 unstaget 파일 file2이 기억으로 그러나 부드럽게

[bar]$ git pull 
remote: Counting objects: 3, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From /tmp/foo 
    5f7d6b3..183c4a5 master  -> origin/master 
Updating 5f7d6b3..183c4a5 
Fast-forward 
file1 | 2 +- 
1 file changed, 1 insertion(+), 1 deletion(-) 
[bar]$ git st 
On branch master 
Your branch is up-to-date with 'origin/master'. 

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: file2 

no changes added to commit (use "git add" and/or "git commit -a") 

간다 단어 world)

[bar]$ cd ../foo/ 
[foo]$ echo World > file2 
[foo]$ git commit -am "add World" 
[master 7cb10c9] add World 
1 file changed, 1 insertion(+), 1 deletion(-) 
[foo]$ cd ../bar/ 
[bar]$ git pull 
remote: Counting objects: 3, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From /tmp/foo 
    183c4a5..7cb10c9 master  -> origin/master 
Updating 183c4a5..7cb10c9 
error: Your local changes to the following files would be overwritten by merge: 
    file2 
Please, commit your changes or stash them before you can merge. 
Aborting 

당김이 예상대로 실패합니다.

+1

이것은 OP의 질문에 대답하지 않습니다 –

+0

예 - 대답은 미완전 된 커밋 된 변경 사항에 관한 것입니다. 질문은 무단 변경에 관한 것입니다. – twotwotwo

+0

답변을 다시 읽으십시오, 그것은 무단 변경에 관한 것입니다. 몇 가지 설명을 추가하고 마지막에 커밋 메시지를 변경했습니다. – Fredszaq