推定
最近の変更がインデックスに追加されているか、または追加されていません。今、私はHEADに新しいコミットを作成せずに特定のコミットを選んでいます...
git cherry-pick -n <commit>
チェリーピックの変更をインデックスから削除するにはどうすればよいですか? 私はできる
git reset HEAD
しかし、以前に追加したすべての変更をやり直さなければなりません。
目的
スタッシュを行う場合、スタッシュをリモートにプッシュすることはできません。現在の WIP を別のシステムのリモートから取得して操作することはできません。そのため、各スタッシュにブランチを使用していることを除いて、git-stash をシミュレートするシェル関数を作成しました。
apply
orは通常、隠したpop
変更を WIP に適用しますが、現在のインデックスには適用しません。stash ブランチからの変更を適用するためにチェリー ピックを使用している間、これらの変更はすべてインデックスに追加され、後でインデックスから削除する必要があります。
編集 (2018-01-29)
@torek さんの回答を読んで理解しました。それでも、以前に使用した bash 関数を共有したいと思います。
function git-stash {
local gitbranch="$( git branch | grep \* )"
local currentbranch="$( [ "${gitbranch}" == "* (HEAD"* ] && echo "${gitbranch}" | cut -d ' ' -f5 | cut -d ')' -f1 || echo "${gitbranch}" | cut -d ' ' -f2- )"
local stashname="stash/$( date +%s )"
git stash save -u ${stashname}
git checkout -b ${stashname}
git stash pop
git add .
[ ${1} ] && git commit -m "WIP: "$1 || git commit -m "WIP"
git checkout ${currentbranch}
}
function git-stash-apply {
local stashbranches="$( git branch | grep stash/ | cut -d ' ' -f3- | sort -r )"
local stashbranches=(${stashbranches[@]})
local lateststashbranch="${stashbranches[0]}"
git cherry-pick -n "${lateststashbranch}"
}
function git-stash-pop {
local stashbranches="$( git branch | grep stash/ | cut -d ' ' -f3- | sort -r )"
local stashbranches=(${stashbranches[@]})
local lateststashbranch="${stashbranches[0]}"
git cherry-pick -n "${lateststashbranch}"
git branch -D "${lateststashbranch}"
git push origin :"${lateststashbranch}"
}
これはまだ適切な解決策ではありませんstash pop
。