-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforcepusher
executable file
·42 lines (37 loc) · 1.49 KB
/
forcepusher
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
34
35
36
37
38
39
40
41
42
#!/usr/bin/env sh
forcepush() {
git add .
git commit -m "$1" || git commit --amend -m "$1";
git reset "$(git commit-tree HEAD^\{tree\} -m "$1")"
git reflog expire --expire=now --all
git gc --aggressive --prune=now
git push -f || {
confirm 'Failed to force push. If the message above said that no upstream remote is set, we can try setting upstream to "origin" and then again attempt to force push. Do you want that? (y/n)' && \
git push -uf origin HEAD || exit 1;
}
}
confirm() {
printf "%s\n" "$1";
old_stty_cfg=$(stty -g)
stty raw -echo
answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
stty "$old_stty_cfg"
if [ "$answer" != "${answer#[Yy]}" ];then
true;
else
false;
fi
}
COMMIT_MSG="${1:-Personal homepage.}"
echo "Commit message to use:
$COMMIT_MSG
To customize this, use the commit message as first argument.
"
confirm 'This is a desctructive operation. This script will:
- Completely purge your git repository history...
- ...including reflog!
- This means that you probably will not be able to recover any of your git history (file system forensics aside).
- It will also attempt to force push to your default remote at the end, overwriting any history at the remote. NEVER DO THIS IN A COLLABORATIVE REPOSITORY!
- Existing .gitignore is of course untouched and respected
Please confirm that you understand and really intend to do this: (y/n)' || { echo 'Quitting on user request.'; exit; };
forcepush "$COMMIT_MSG"