12
[--index-filter <command>] [--parent-filter <command>]
13
[--msg-filter <command>] [--commit-filter <command>]
14
[--tag-name-filter <command>] [--subdirectory-filter <directory>]
15
- [-d <directory>] <new-branch-name> [<rev-list options>...]
15
+ [-d <directory>] [-f | --force] [<rev-list options>...]
16
17
DESCRIPTION
18
-----------
26
The command takes the new branch name as a mandatory argument and
27
the filters as optional arguments. If you specify no filters, the
28
commits will be recommitted without any changes, which would normally
29
-have no effect and result in the new branch pointing to the same
30
-branch as your current branch. Nevertheless, this may be useful in
31
-the future for compensating for some git bugs or such, therefore
32
-such a usage is permitted.
29
+have no effect. Nevertheless, this may be useful in the future for
30
+compensating for some git bugs or such, therefore such a usage is
31
+permitted.
32
33
*WARNING*! The rewritten history will have different object names for all
34
the objects and will not converge with the original branch. You will not
37
full implications, and avoid using it anyway, if a simple single commit
38
would suffice to fix your problem.
39
41
-Always verify that the rewritten version is correct before disposing
42
-the original branch.
40
+Always verify that the rewritten version is correct: The original refs,
41
+if different from the rewritten ones, will be stored in the namespace
42
+'refs/original/'.
43
44
Note that since this operation is extensively I/O expensive, it might
45
be a good idea to redirect the temporary directory off-disk, e.g. on
142
does this in the '.git-rewrite/' directory but you can override
143
that choice by this parameter.
144
145
+-f\|--force::
146
+ `git filter-branch` refuses to start with an existing temporary
147
+ directory or when there are already refs starting with
148
+ 'refs/original/', unless forced.
149
+
150
<rev-list-options>::
151
When options are given after the new branch name, they will
152
be passed to gitlink:git-rev-list[1]. Only commits in the resulting
161
or copyright violation) from all commits:
162
163
-------------------------------------------------------
159
-git filter-branch --tree-filter 'rm filename' newbranch
164
+git filter-branch --tree-filter 'rm filename' HEAD
165
-------------------------------------------------------
166
167
A significantly faster version:
168
164
--------------------------------------------------------------------------------
165
-git filter-branch --index-filter 'git update-index --remove filename' newbranch
166
--------------------------------------------------------------------------------
169
+--------------------------------------------------------------------------
170
+git filter-branch --index-filter 'git update-index --remove filename' HEAD
171
+--------------------------------------------------------------------------
172
173
Now, you will get the rewritten history saved in the branch 'newbranch'
174
(your current branch is left untouched).
177
history) to be the parent of the current initial commit, in
178
order to paste the other history behind the current history:
179
175
-------------------------------------------------------------------------
176
-git filter-branch --parent-filter 'sed "s/^\$/-p <graft-id>/"' newbranch
177
-------------------------------------------------------------------------
180
+-------------------------------------------------------------------
181
+git filter-branch --parent-filter 'sed "s/^\$/-p <graft-id>/"' HEAD
182
+-------------------------------------------------------------------
183
184
(if the parent string is empty - therefore we are dealing with the
185
initial commit - add graftcommit as a parent). Note that this assumes
186
history with a single root (that is, no merge without common ancestors
187
happened). If this is not the case, use:
188
184
--------------------------------------------------------------------------------
189
+--------------------------------------------------------------------------
190
git filter-branch --parent-filter \
186
- 'cat; test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>"' newbranch
187
--------------------------------------------------------------------------------
191
+ 'cat; test $GIT_COMMIT = <commit-id> && echo "-p <graft-id>"' HEAD
192
+--------------------------------------------------------------------------
193
194
or even simpler:
195
196
-----------------------------------------------
197
echo "$commit-id $graft-id" >> .git/info/grafts
193
-git filter-branch newbranch $graft-id..
198
+git filter-branch $graft-id..HEAD
199
-----------------------------------------------
200
201
To remove commits authored by "Darl McBribe" from the history:
213
done;
214
else
215
git commit-tree "$@";
211
- fi' newbranch
216
+ fi' HEAD
217
------------------------------------------------------------------------------
218
219
The shift magic first throws away the tree id and then the -p
243
To rewrite only commits D,E,F,G,H, but leave A, B and C alone, use:
244
245
--------------------------------
241
-git filter-branch ... new-H C..H
246
+git filter-branch ... C..H
247
--------------------------------
248
249
To rewrite commits E,F,G,H, use one of these:
250
251
----------------------------------------
247
-git filter-branch ... new-H C..H --not D
248
-git filter-branch ... new-H D..H --not C
252
+git filter-branch ... C..H --not D
253
+git filter-branch ... D..H --not C
254
----------------------------------------
255
256
To move the whole tree into a subdirectory, or remove it from there:
260
'git ls-files -s | sed "s-\t-&newsubdir/-" |
261
GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
262
git update-index --index-info &&
258
- mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' directorymoved
263
+ mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' HEAD
264
---------------------------------------------------------------
265
266