Programing

자식 숨김을 어떻게 이름을 바꿀 수 있습니까?

crosscheck 2020. 5. 25. 21:01
반응형

자식 숨김을 어떻게 이름을 바꿀 수 있습니까?


이름이 잘못된 숨김이 있습니다. 정확한 이름을 수정하고 싶습니다.

숨김의 이름을 바꾸려면 어떻게해야합니까?


숨김 목록이 다음과 같다고 가정 해 봅시다.

$ git stash list
stash@{0}: WIP on master: Add some very important feature 
stash@{1}: WIP on master: Fix some silly bug

먼저 이름을 바꾸려는 숨김 항목을 제거해야합니다.

$ git stash drop stash@{1}
Dropped stash@{1} (af8fdeee49a03d1b4609f294635e7f0d622e03db)

이제 삭제 후 반환 된 커밋 sha를 사용하여 새 메시지로 다시 추가하십시오.

$ git stash store -m "Very descriptive message" af8fdeee49a03d1b4609f294635e7f0d622e03db

그리고 그게 다야:

$ git stash list
stash@{0}: Very descriptive message
stash@{1}: WIP on master: Add some very important feature

이 솔루션에는 git 1.8.4 이상이 필요하며 더러워진 작업 디렉토리에서도 작동합니다.


수동으로 수행하거나 Git 개선에 기여하지 않는 한 별칭을 사용할 수 있습니다.

git config --global alias.stash-rename '!_() { rev=$(git rev-parse $1) && git stash drop $1 || exit 1 ; git diff-index --quiet HEAD; s=$?; [ $s != 0 ] && git stash save "tmp stash from stash-rename"; git stash apply $rev && shift && git stash save "$@" && [ $s != 0 ] && git stash pop stash@{1}; }; _'

사용법 : " git stash-rename <stash> [save options] [<message>]"

[save options]의 옵션 git stash save:[-p|--patch] [-k|--[no-]keep-index] [-q|--quiet] [-u|--include-untracked] [-a|--all]

예:

$ git stash list
stash@{0}: On master: Pep8 format
stash@{1}: On master: co other than master with local changes
stash@{2}: On master: tests with deployAtEnd

# Let's say I want to rename the stash@{2} adding an issue reference:
$ git stash-rename stash@{2} NXP-13971-deployAtEnd

$ git stash list
stash@{0}: On master: NXP-13971-deployAtEnd
stash@{1}: On master: Pep8 format
stash@{2}: On master: co other than master with local changes

로컬 스테이지되지 않은 변경 사항이 있어도 작동합니다. :)

2016/02/22 수정

단순화 된 스크립트, qzb의 크레딧 , https://stackoverflow.com/a/35549615/515973

git config --global alias.stash-rename '!_() { rev=$(git rev-parse $1) && git stash drop $1 || exit 1 ; git stash store -m "$2" $rev; }; _'

사용법 : " git stash-rename <stash> [<message>]"


그렇게 할 수 있다고 생각하지 않습니다. 숨김 이름 바꾸기대한 제안이 있었지만 아직 구현되지 않았습니다.

내 일반적인 아이디어는 다음과 같습니다

  1. git reflog update특정 reflog 항목과 관련된 메시지를 업데이트 하는 새 명령을 구현 하십시오. 이를 위해 새로운 update_reflog_ent()기능 ( reflog.c )은 업데이트 할 특정 reflog 항목과 관련된 메시지를 변경합니다. update_reflog()기능을 사용하는 것 for_each_reflog_ent()update_reflog_ent실제로 변화를 수행합니다.

  2. git stash rename명령 만 호출 할 필요가 git reflog update적절한 심판과 새 메시지와 함께.

또는 당신은 물론 숨길 수 있고 git stash save [message]


독자의 이익 을 위해 현재 승인 된 정답에 대한 확장 입니다.

스 태쉬 메시지를 정정 할뿐만 아니라 스 태쉬의 커밋 메시지도 정정하려는 경우,

git stash list

git log --oneline -1 stash

둘 다 표시되는 것에 동의하며 조금 더 필요합니다. 더 좋은 방법이있을 수 있지만 여기의 조리법은 이해하기 쉽습니다.

git commit --amend당신 이 할 수 있으려면 지점의 팁에 있어야합니다. 따라서 해결책은 다음과 같습니다.

git checkout -b scratch stash@{1}
git stash drop stash@{1}
git commit --amend -m "$MESSAGE"
git stash store -m "$MESSAGE" HEAD
git checkout master
git branch -D scratch

설명 :

  • "문제가있는 스 태쉬"에서 새 (아직 존재하지 않는) "스크래치"브랜치를 작성하고 전환하십시오.
  • 오래된 은신처를 제거하십시오. 우리는 여전히 지점에 이것을 가지고 있기 때문에 이것은 안전합니다.
  • git commit --amend커밋 메시지를 바꾸는 데 사용 , "문제가있는 스 태쉬"의 SHA 변경
  • qzb의 답변 에 따라 숨김을 저장하십시오.
  • 다시 전환 ( "마스터"에서 온 것으로 가정) 및 정리

단점 :

  • This switches branches temporarily. So this recipe can only be applied when git status --porcelain is clean (read: does not output anything)

  • It renumbers the stashes, so the changed stash becomes stash@{0}

  • You need to enter the $MESSAGE twice or use some environment variable (in the example: MESSAGE)

  • You need to find an unused branch name

There are ways to do this without switching branches, but this is beyond the scope of this answer.

Example

git init scratch
cd scratch
for a in A B C D; do date >$a; git add $a; git commit -m $a; done
for a in X Y; do echo $a > Z; git stash save --all; done
git log --oneline --graph --decorate --all; git stash list

Output

*-.   e0e281b (refs/stash) WIP on master: 8bdcc32 D
|\ \  
| | * 4d62f52 untracked files on master: 8bdcc32 D
| * 096f158 index on master: 8bdcc32 D
|/  
* 8bdcc32 (HEAD, master) D
* c84c659 C
* 49bb2da B
* b1852c6 A
stash@{0}: WIP on master: 8bdcc32 D
stash@{1}: WIP on master: 8bdcc32 D

Now without changing commit (note: the SHA in following will be different at your side):

git stash drop stash@{1}
git stash store -m ...changed... 2fbf9007dfdfb95ae269a19e13b8b9ca3e24181c
git log --oneline --graph --decorate --all; git stash list

Output

*-.   2fbf900 (refs/stash) WIP on master: 8bdcc32 D
|\ \  
| | * 246dc5c untracked files on master: 8bdcc32 D
| * 80c5ea0 index on master: 8bdcc32 D
|/  
* 8bdcc32 (HEAD, master) D
* c84c659 C
* 49bb2da B
* b1852c6 A
stash@{0}: ...changed...
stash@{1}: WIP on master: 8bdcc32 D

As you can see, stash@{0} still is shown as 2fbf900 (refs/stash) WIP on master: 8bdcc32 D in git log. If you look carefully, you will see, that several commits have changed SHA. This is due to how stashes are handled (parents are included of the SHA, and stashes have their stashes as parent).

Fix that:

git checkout -b scratch stash
git stash drop
git commit --amend -m ...changed...
git stash store -m ...changed... HEAD
git checkout master
git branch -D scratch
git log --oneline --graph --decorate --all; git stash list

Output

*-.   4d55186 (refs/stash) ...changed...
|\ \  
| | * 246dc5c untracked files on master: 8bdcc32 D
| * 80c5ea0 index on master: 8bdcc32 D
|/  
* 8bdcc32 (HEAD, master) D
* c84c659 C
* 49bb2da B
* b1852c6 A
stash@{0}: ...changed...
stash@{1}: WIP on master: 8bdcc32 D

As you also can see, refs/stash has a changed SHA, too.


Here is a modified version of Julien's alias that lets you properly deal with the On <branch> prefix usually prepended to stash names:

git config --global alias.stash-rename '!_() { newmsg="$1" && stash=${2:-"stash@{0}"} && newbranch="$3" && sha=$(git rev-parse "$stash") && olddesc="$(git stash list --format=%gs -1 "$stash")" && newdesc="$(if [[ "$newbranch" = "." ]]; then echo "$newmsg"; else if [[ -n "$newbranch" ]]; then echo "On $newbranch: $newmsg"; else if [[ "$olddesc" =~ ":" ]]; then echo "$(echo "$olddesc" | cut -f1 -d":"): $newmsg"; else echo "$newmsg"; fi; fi; fi)" && git stash drop "$stash" > /dev/null || exit 1; git stash store -m "$newdesc" "$sha" && git stash list; }; _'

Syntax:

git stash-rename <new-name> [<stash> [<new-branch-name> | .]]

Example usage:

repo[master] % touch tmp && git add tmp && git stash save first
Saved working directory and index state On master: first
HEAD is now at bd62064 Initial commit
repo[master] % touch tmp && git add tmp && git stash save second
Saved working directory and index state On master: second
HEAD is now at bd62064 Initial commit
repo[master] % git stash list
stash@{0}: On master: second
stash@{1}: On master: first
repo[master] % git stash-rename renamed
stash@{0}: On master: renamed
stash@{1}: On master: first
repo[master] % git stash-rename also-renamed stash@{1}
stash@{0}: On master: also-renamed
stash@{1}: On master: renamed
repo[master] % git stash-rename branch-changed stash@{0} new-branch
stash@{0}: On new-branch: branch-changed
stash@{1}: On master: renamed
repo[master] % git stash-rename branch-name-persists
stash@{0}: On new-branch: branch-name-persists
stash@{1}: On master: renamed
repo[master] % git stash-rename no-branch stash@{0} .
stash@{0}: no-branch
stash@{1}: On master: renamed
repo[master] % git stash-rename renamed
stash@{0}: renamed
stash@{1}: On master: renamed
repo[master] % git stash-rename readd-branch stash@{0} develop
stash@{0}: On develop: readd-branch
stash@{1}: On master: renamed

Most of the command is for parsing the arguments and figuring out what should be done to the branch name. The git tools used are as follows:

  • git rev-parse <stash> to find the SHA of the stash.
  • git stash list --format=%gs -1 <stash> to find the reflog subject of the stash. Note that this is different from the commit message of the stash, which is not changed by this command. The reflog subject is what shows up in git stash list, and you can change the reflog subject without changing the hashes of the commits associated with the stashes. However, you can always find the original commit message, so don't use git stash-rename to remove sensitive information!
  • git stash drop <stash> to drop the old reference to the stash (but we still have the SHA, so it's not lost).
  • git stash store -m <new-message> <sha> to save a new reference to the stash with the same commit information but a different reflog subject.
  • git stash list to list the stashes after the operation is finished. Note that new stashes are always pushed to the beginning of the list. It would be necessary to re-push all the stashes before the stash of interest in order to restore its original position.

It's very simple. First, undo the last stash with:

git stash pop

After this, yo can save the stash with a customized name in this way:

git stash save "your explanatory name"

I hope it useful for you. :)


Simplest way: pop your stash with git stash pop then save it again with git stash save your-name

참고URL : https://stackoverflow.com/questions/25931026/how-can-i-rename-a-git-stash

반응형