认为
我最近添加或未添加到索引中的更改。现在我正在挑选一个特定的提交而不在我的 HEAD 上创建一个新的提交......
git cherry-pick -n <commit>
如何从索引中删除精选更改?我可以做一个
git reset HEAD
但我必须重做我之前添加的所有更改。
目的
如果一个人进行了存储,则无法将存储推送到遥控器。当前的 WIP 无法从另一个系统上的远程拉出以进行处理。所以我编写了 shell 函数来模拟 git-stash,除了我为每个存储使用分支。
apply
或通常会将隐藏的pop
更改应用于 WIP,但不会应用于当前索引。当我使用樱桃挑选来应用存储分支中的更改时,所有这些更改都将添加到索引中,之后我需要将它们从索引中删除。
编辑 (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
.