Skip to content

Commit 1f374d1

Browse files
committed
Merge pull request #412 from spacewander/git-obliterate
update git obliterate
2 parents 1aadd1c + d5e10f6 commit 1f374d1

File tree

4 files changed

+256
-2
lines changed

4 files changed

+256
-2
lines changed

bin/git-obliterate

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
#!/usr/bin/env bash
2-
file="$1"
2+
3+
file=""
4+
range=""
5+
for i in "$@"
6+
do
7+
# use '--' to seperate file list and rev-list arguments
8+
test "$i" == '--' && shift && break
9+
file="$file"' '"$i"
10+
shift
11+
done
12+
test -n "$*" && range="$*"
13+
314
test -z "$file" && echo "file required." 1>&2 && exit 1
4-
git filter-branch -f --index-filter "git rm -r --cached '$file' --ignore-unmatch" --prune-empty --tag-name-filter cat -- --all
15+
if [ -z "$range" ]
16+
then
17+
git filter-branch -f --index-filter "git rm -r --cached ""$file"" --ignore-unmatch" \
18+
--prune-empty --tag-name-filter cat -- --all
19+
else
20+
# don't quote $range so that we can forward multiple rev-list arguments
21+
git filter-branch -f --index-filter "git rm -r --cached ""$file"" --ignore-unmatch" \
22+
--prune-empty --tag-name-filter cat -- $range
23+
fi

man/git-obliterate.1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-OBLITERATE" "1" "August 2015" "" ""
5+
.
6+
.SH "NAME"
7+
\fBgit\-obliterate\fR \- rewrite past commits to remove some files
8+
.
9+
.SH "SYNOPSIS"
10+
git obliterate <files\.\.\.> [\-\- <rev\-list options\.\.\.>]
11+
.
12+
.SH "DESCRIPTION"
13+
Completely remove some files from the repository, including past commits and tags\. WARNING! This command will rewirte the history similar to \fBgit rebase\fR(though it affects more)\. The rewritten history will have different object names for all the objects and will not converge with the original branch\. So \fBavoid using it on commits that you shared\fR\. And it will mess up stash, so \fBdon\'t have stash when you run \fBgit obliterate\fR\fR\.
14+
.
15+
.SH "OPTIONS"
16+
You can pass rev\-list options to indicate the range of commits affected\. Those options need to be seperated with \'\-\-\' before them\. Run \fBgit help rev\-list\fR to see the acceptable options\.
17+
.
18+
.SH "Examples"
19+
Remove \.secret from the repository:
20+
.
21+
.IP "" 4
22+
.
23+
.nf
24+
25+
$ git obliterate \.secret
26+
.
27+
.fi
28+
.
29+
.IP "" 0
30+
.
31+
.P
32+
Remove \.secret from commits between origin and feature:
33+
.
34+
.IP "" 4
35+
.
36+
.nf
37+
38+
$ git obliterate \.secret \-\- feature ^origin
39+
.
40+
.fi
41+
.
42+
.IP "" 0
43+
.
44+
.P
45+
Remove \.secret from commit abcdefg to commit 1234567
46+
.
47+
.IP "" 4
48+
.
49+
.nf
50+
51+
$ git obliterate \.secret \-\- abcdefg\.\.1234567
52+
.
53+
.fi
54+
.
55+
.IP "" 0
56+
.
57+
.SH "AUTHOR"
58+
Written by <\fIbrianloveswords@gmail\.com\fR>
59+
.
60+
.SH "REPORTING BUG"
61+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
62+
.
63+
.SH "SEE ALSO"
64+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-obliterate.1.html

Lines changed: 129 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-obliterate.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
git-obliterate(1) -- rewrite past commits to remove some files
2+
===============================
3+
4+
## SYNOPSIS
5+
6+
git obliterate &lt;files...&gt; [-- &lt;rev-list options...&gt;]
7+
8+
## DESCRIPTION
9+
10+
Completely remove some files from the repository, including past commits and tags.
11+
WARNING! This command will rewirte the history similar to `git rebase`(though it affects more). The rewritten history will have different object names for all the objects and will not converge with the original branch. So **avoid using it on commits that you shared**.
12+
And it will mess up stash, so **don't have stash when you run `git obliterate`**.
13+
14+
## OPTIONS
15+
16+
You can pass rev-list options to indicate the range of commits affected. Those options need to be seperated with '--' before them. Run `git help rev-list` to see the acceptable options.
17+
18+
## Examples
19+
20+
Remove .secret from the repository:
21+
22+
$ git obliterate .secret
23+
24+
Remove .secret from commits between origin and feature:
25+
26+
$ git obliterate .secret -- feature ^origin
27+
28+
Remove .secret from commit abcdefg to commit 1234567
29+
30+
$ git obliterate .secret -- abcdefg..1234567
31+
32+
## AUTHOR
33+
34+
Written by &lt;<[email protected]>&gt;
35+
36+
## REPORTING BUG
37+
38+
&lt;<https://github.com/tj/git-extras/issues>&gt;
39+
40+
## SEE ALSO
41+
42+
&lt;<https://github.com/tj/git-extras>&gt;

0 commit comments

Comments
 (0)