-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitpackup
More file actions
33 lines (27 loc) · 899 Bytes
/
gitpackup
File metadata and controls
33 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
# packup current branch to change off it
function exitlikethis
{
echo $1 >&2
exit 1
}
branch=$(branch)
if git status | head -20 | grep '^Changes ' > /dev/null; then
stashybranch=`date +'stash_%Y_%m_%d_%H_%M_%S'`
# git branch -D "$stashybranch"
git checkout -b "$stashybranch" || exitlikethis "Failed to create faux stash branch $stashybranch"
git add -u
git commit -m "backing up uncommitted changes"
echo STASH BRANCH CREATED HERE: $stashybranch
echo IF THERE IS TROUBLE LATER RESTORE WITH:
thisdir=$(pwd)
cat > ../_restore.sh <<EOFRESTORE
cd "$thisdir"
git checkout "$branch"
git merge "$stashybranch" --no-commit --no-ff
git branch -D "$stashybranch"
EOFRESTORE
cat ../_restore.sh
echo OR JUST RUN sh ../_restore.sh
git checkout "$branch" || exitlikethis "Failed to re-checkout branch $branch"
fi