카테고리 보관물: Git

Git

자식 숨김-> 숨김 변경 사항을 현재 변경 사항과 병합 해당 지점에 필요한 다른

지점을 변경하고 해당 지점에 필요한 다른 변경 사항을 숨겼다는 사실을 깨달았습니다. 내가 원하는 것은 숨김 변경 사항을 현재 변경 내용과 병합하는 방법입니다.

이 방법이 있습니까?

편의상, 나는 결국 현재의 변경 사항을 포기하고 커밋 한 다음 내 변경 사항을 커밋했지만 한 번의 실패로 변경하는 것을 선호했을 것입니다.



답변

나는 당신의 커밋되지 않은 변경 사항이 인덱스에 추가하는 경우 (예를 사용하여, “무대”는 것을 발견 git add ...한 후,) git stash apply(, 아마, 그리고 git stash pop실제로 적절한 병합을 할 것입니다). 충돌이 없으면 황금색입니다. 그렇지 않은 경우 평소와 git mergetool같이 또는 편집기를 사용하여 수동으로 해결하십시오 .

분명히, 이것은 내가 말하고있는 과정입니다.

mkdir test-repo && cd test-repo && git init
echo test > test.txt
git add test.txt && git commit -m "Initial version"

# here's the interesting part:

# make a local change and stash it:
echo test2 > test.txt
git stash

# make a different local change:
echo test3 > test.txt

# try to apply the previous changes:
git stash apply
# git complains "Cannot apply to a dirty working tree, please stage your changes"

# add "test3" changes to the index, then re-try the stash:
git add test.txt
git stash apply
# git says: "Auto-merging test.txt"
# git says: "CONFLICT (content): Merge conflict in test.txt"

… 아마도 당신이 찾고있는 것입니다.


tl; dr

git add먼저 실행하십시오 .


답변

실행 git stash pop중이거나 git stash apply본질적으로 병합입니다. 숨김에서 변경된 파일이 작업 사본에서도 변경되지 않는 한 현재 변경 사항을 커밋하지 않아도됩니다.이 경우이 오류 메시지가 표시됩니다.

error: Your local changes to the following files would be overwritten by merge:
       file.txt
Please, commit your changes or stash them before you can merge.
Aborting

이 경우 한 단계에서 현재 변경 사항에 숨김을 적용 할 수 없습니다. 커밋 git rebase을 정말로 원하지 않으면 변경 사항을 커밋하고, 스 태쉬를 적용하고, 커밋하고,이 두 커밋을 스쿼시 할 수 있지만, 이는 더 가치가있는 문제 일 수 있습니다.


답변

내가 원하는 것은 숨김 변경 사항을 현재 변경 사항과 병합하는 방법입니다.

다른 옵션은 다음과 같습니다.

git stash show -p|git apply
git stash drop

git stash show -p마지막으로 저장된 숨김의 패치가 표시됩니다. git apply적용합니다. 병합이 완료되면를 사용하여 병합 된 숨김을 삭제할 수 있습니다 git stash drop.


답변

내가 이것을하는 방법은 git add이것에 처음 git stash apply <stash code>이다. 가장 간단한 방법입니다.


답변

@Brandan이 제안한 것처럼, 여기에 내가 돌아 다니기 위해해야했던 것이 있습니다.

error: Your local changes to the following files would be overwritten by merge:
       file.txt
Please, commit your changes or stash them before you can merge.
Aborting

이 과정을 따르십시오 :

git status  # local changes to `file`
git stash list  # further changes to `file` we want to merge
git commit -m "WIP" file
git stash pop
git commit -m "WIP2" file
git rebase -i HEAD^^  # I always use interactive rebase -- I'm sure you could do this in a single command with the simplicity of this process -- basically squash HEAD into HEAD^
# mark the second commit to squash into the first using your EDITOR
git reset HEAD^

또한에 대한 완전히 통합 된 로컬 변경 사항 이 남아 있으므로 file추가 작업 / 정리를 수행하거나 단일 커밋을 수행 할 수 있습니다. 또는의 병합 된 내용 file이 올바르다는 것을 알고 있으면 피팅 메시지를 작성하고 건너 뛸 수 git reset HEAD^있습니다.


답변

아마도 (difftool을 통해) … 예 … 지점에서 병합하는 것은 최악의 생각이 아닙니다!

> current_branch=$(git status | head -n1 | cut -d' ' -f3)
> stash_branch="$current_branch-stash-$(date +%yy%mm%dd-%Hh%M)"
> git stash branch $stash_branch
> git checkout $current_branch
> git difftool $stash_branch


답변

당신은 쉽게 할 수 있습니다

  1. 현재 변경 사항을 커밋
  2. 숨겨 놓지 말고 갈등을 해결하십시오
  3. 숨김에서 변경 사항 커밋
  4. 커밋을위한 소프트 리셋 (마지막 올바른 커밋)