Skip to content

Commit b0fa7ab

Browse files
chriscoolgitster
authored andcommitted
git: add --no-replace-objects option to disable replacing
Commit dae556b (environment: add global variable to disable replacement) adds a variable to enable/disable replacement, and it is enabled by default for most commands. So there is no way to disable it for some commands, which is annoying when we want to get information about a commit that has been replaced. For example: $ git cat-file -p N would output information about the replacement commit if commit N is replaced. With the "--no-replace-objects" option that this patch adds it is possible to get information about the original commit using: $ git --no-replace-objects cat-file -p N While at it, let's add some documentation about this new option in the "git replace" man page too. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78d553b commit b0fa7ab

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

Documentation/git-replace.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,26 @@ replacement object.
2323
Unless `-f` is given, the replace reference must not yet exist in
2424
`.git/refs/replace/` directory.
2525

26+
Replace references will be used by default by all git commands except
27+
those doing reachability traversal (prune, pack transfer and fsck).
28+
29+
It is possible to disable use of replacement refs for any command
30+
using the --no-replace-objects option just after "git".
31+
32+
For example if commit "foo" has been replaced by commit "bar":
33+
34+
------------------------------------------------
35+
$ git --no-replace-object cat-file commit foo
36+
------------------------------------------------
37+
38+
show information about commit "foo", while:
39+
40+
------------------------------------------------
41+
$ git cat-file commit foo
42+
------------------------------------------------
43+
44+
show information about commit "bar".
45+
2646
OPTIONS
2747
-------
2848
-f::
@@ -54,6 +74,7 @@ SEE ALSO
5474
--------
5575
linkgit:git-tag[1]
5676
linkgit:git-branch[1]
77+
linkgit:git[1]
5778

5879
Author
5980
------

Documentation/git.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]
13-
[-p|--paginate|--no-pager]
13+
[-p|--paginate|--no-pager] [--no-replace-objects]
1414
[--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]
1515
[--help] COMMAND [ARGS]
1616

@@ -237,6 +237,10 @@ help ...`.
237237
environment is not set, it is set to the current working
238238
directory.
239239

240+
--no-replace-objects::
241+
Do not use replacement refs to replace git objects. See
242+
linkgit:git-replace[1] for more information.
243+
240244

241245
FURTHER DOCUMENTATION
242246
---------------------

git.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
const char git_usage_string[] =
88
"git [--version] [--exec-path[=GIT_EXEC_PATH]] [--html-path]\n"
9-
" [-p|--paginate|--no-pager]\n"
9+
" [-p|--paginate|--no-pager] [--no-replace-objects]\n"
1010
" [--bare] [--git-dir=GIT_DIR] [--work-tree=GIT_WORK_TREE]\n"
1111
" [--help] COMMAND [ARGS]";
1212

@@ -87,6 +87,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
8787
use_pager = 0;
8888
if (envchanged)
8989
*envchanged = 1;
90+
} else if (!strcmp(cmd, "--no-replace-objects")) {
91+
read_replace_refs = 0;
9092
} else if (!strcmp(cmd, "--git-dir")) {
9193
if (*argc < 2) {
9294
fprintf(stderr, "No directory given for --git-dir.\n" );

t/t6050-replace.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ test_expect_success 'replace the author' '
7070
git show $HASH2 | grep "O Thor"
7171
'
7272

73+
test_expect_success 'test --no-replace-objects option' '
74+
git cat-file commit $HASH2 | grep "author O Thor" &&
75+
git --no-replace-objects cat-file commit $HASH2 | grep "author A U Thor" &&
76+
git show $HASH2 | grep "O Thor" &&
77+
git --no-replace-objects show $HASH2 | grep "A U Thor"
78+
'
79+
7380
cat >tag.sig <<EOF
7481
object $HASH2
7582
type commit

0 commit comments

Comments
 (0)