Git로 변경 한 여러 파일에서 하나의 파일 만 숨기십시오.
질문
내 지점에서 여러 개의 변경된 파일 중 하나만 숨길 수 있습니까?
답변
git stash push -p -m "my commit message"
-P 숨겨져 있어야하는 헌크를 선택하겠습니다.전체 파일도 선택할 수 있습니다.
각 덩어리에 대한 몇 가지 조치를 취하는 메시지가 표시됩니다.
y - stash this hunk
n - do not stash this hunk
q - quit; do not stash this hunk or any of the remaining ones
a - stash this hunk and all later hunks in the file
d - do not stash this hunk or any of the later hunks in the file
g - select a hunk to go to
/ - search for a hunk matching the given regex
j - leave this hunk undecided, see next undecided hunk
J - leave this hunk undecided, see next hunk
k - leave this hunk undecided, see previous undecided hunk
K - leave this hunk undecided, see previous hunk
s - split the current hunk into smaller hunks
e - manually edit the current hunk
? - print help
답변
면책 조항 : 다음과 같은 답변은 GIT 2.13 전에 GIT를위한 것입니다.GIT 2.13 이상, 다른 답변을 더 이상 확인하십시오.
경고
의견에서 언급했듯이, 이것은 모든 것을 스테 래시로 옮기고, 단계적으로 안정적으로 멈추게됩니다.억제품이 끝나면 인덱스만으로도 숨겨진 지수가 끝나면됩니다.이로 인해 숨김이 나중에 튀어 나오면 병합 충돌이 발생할 수 있습니다.
이것은 이전에 추가되지 않은 모든 것을 숨길 것입니다.그냥짜리 지키고 싶은 일을 추가 한 다음 실행하십시오.
git stash --keep-index
예를 들어, 이전 커밋을 둘 이상의 변경으로 나누려면 다음 절차를 사용할 수 있습니다.
git rebase -i <last good commit>
- Mark some changes as
edit
. git reset HEAD^
git add <files you want to keep in this change>
git stash --keep-index
- Fix things up as necessary. Don't forget to
git add
any changes. git commit
git stash pop
- Repeat, from #5, as necessary.
git rebase --continue
답변
GIT 2.13 (Q2 2017) 이후로 개별 파일을 숨길 수 있습니다.
git stash push [-m <message>] [--] [<pathspec>...]
PathSpec이 'git stash push'가 주어지면 새로운 숨김은 PathSpec과 일치하는 파일에 대해서만 수정 된 상태를 기록합니다. 자세한 내용은 "특정 파일에 대한 변경 사항 변경"을 참조하십시오.
단순화 된 예 :
git stash push path/to/file
이 기능의 테스트 케이스에는 몇 가지 옵션이 옵션이 표시됩니다.
test_expect_success 'stash with multiple pathspec arguments' '
>foo &&
>bar &&
>extra &&
git add foo bar extra &&
git stash push -- foo bar &&
test_path_is_missing bar &&
test_path_is_missing foo &&
test_path_is_file extra &&
git stash pop &&
test_path_is_file foo &&
test_path_is_file bar &&
test_path_is_file extra
The original answer (below, June 2010) was about manually selecting what you want to stash.
Casebash comments:
This (the
stash --patch
original solution) is nice, but often I've modified a lot of files so using patch is annoying
bukzor's answer (upvoted, November 2011) suggests a more practical solution, based on
git add
+ git stash --keep-index
.
Go see and upvote his answer, which should be the official one (instead of mine).
About that option, chhh points out an alternative workflow in the comments:
you should "
git reset --soft
" after such a stash to get your clear staging back:
In order to get to the original state - which is a clear staging area and with only some select un-staged modifications, one could softly reset the index to get (without committing anything like you - bukzor - did).
(Original answer June 2010: manual stash)
Yet, git stash save --patch
could allows you to achieve the partial stashing you are after:
With
--patch
, you can interactively select hunks from in the diff between HEAD and the working tree to be stashed.
The stash entry is constructed such that its index state is the same as the index state of your repository, and its worktree contains only the changes you selected interactively. The selected changes are then rolled back from your worktree.
However that will save the full index (which may not be what you want since it might include other files already indexed), and a partial worktree (which could look like the one you want to stash).
git stash --patch --no-keep-index
might be a better fit.
If --patch
doesn't work, a manual process might:
For one or several files, an intermediate solution would be to:
- copy them outside the Git repo
(Actually, eleotlecram proposes an interesting alternative) git stash
- copy them back
git stash
# this time, only the files you want are stashedgit stash pop stash@{1}
# re-apply all your files modificationsgit checkout -- afile
# reset the file to the HEAD content, before any local modifications
At the end of that rather cumbersome process, you will have only one or several files stashed.
답변
다음과 같이 Git Stash Push를 사용하십시오.
git stash push [--] [<pathspec>...]
예를 들어:
git stash push -- my/file.sh
이것은 2017 년 봄에 발표 된 GIT 2.13 이후로 이용 가능합니다.
답변
git stash -p (또는 stash-keep-index와 함께 git add-p add-add)가 너무 번성 할 때, diff, 체크 아웃을 쉽게 사용하는 것이 더 쉽습니다.
특정 파일 / dir만을 "숨김"하려면 다음을 수행하십시오.
git diff path/to/dir > stashed.diff
git checkout path/to/dir
그런 다음 나중에
git apply stashed.diff
답변
3 개의 파일이 있다고 가정 해 봅시다
a.rb
b.rb
c.rb
그리고 당신은 b.rb와 c.rb 만 숨기고 싶지만 a.rb는 아닙니다.
당신은 이렇게 할 수 있습니다
# commit the files temporarily you don't want to stash
git add a.rb
git commit -m "temp"
# then stash the other files
git stash save "stash message"
# then undo the previous temp commit
git reset --soft HEAD^
git reset
그리고 당신은 끝납니다! HTH.
출처:https://stackoverflow.com/questions/3040833/stash-only-one-file-out-of-multiple-files-that-have-changed-with-git
최근댓글