A stash is represented as a commit whose tree records the state of the working directory, and its first parent is the commit at HEAD when the stash was created.
So
git diff stash@{0}^1 stash@{0} -- <filename>
compares a stash to the state when it was stashed
git stash show -p
git checkout stash@{0} -- <filename>
git reset HEAD^ -- path/to/file
git commit --amend --no-edit
git remote prune origin
note: All this does is remove local pointers. In other words, if you type git fetch origin
git will download the refs for all the branches on "origin". The command above removes any refs that no longer exist on origin
git cherry-pick A~1..B
The ~1
is required because A
is not included.
git checkout -q main && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base main $branch) && [[ $(git cherry main $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && git branch -D $branch; done
list which branches would be deleted
git checkout -q main && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base main $branch) && [[ $(git cherry main $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && echo "$branch is merged into main and can be deleted"; done