You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the beginning of the output of the format-patch command that you saw in the previous section.
91
91
This is also a valid mbox email format.
@@ -95,16 +95,17 @@ If you run a mail client that can save several emails out in mbox format, you ca
95
95
However, if someone uploaded a patch file generated via `format-patch` to a ticketing system or something similar, you can save the file locally and then pass that file saved on your disk to `git am` to apply it:
96
96
97
97
[source,console]
98
-
-----
98
+
----
99
99
$ git am 0001-limit-log-function.patch
100
100
Applying: add limit to log function
101
-
-----
101
+
----
102
102
103
103
You can see that it applied cleanly and automatically created the new commit for you.
104
104
The author information is taken from the email's `From` and `Date` headers, and the message of the commit is taken from the `Subject` and body (before the patch) of the email.
105
105
For example, if this patch was applied from the mbox example above, the commit generated would look something like this:
The `Commit` information indicates the person who applied the patch and the time it was applied.
121
122
The `Author` information is the individual who originally created the patch and when it was originally created.
@@ -125,7 +126,7 @@ Perhaps your main branch has diverged too far from the branch the patch was buil
125
126
In that case, the `git am` process will fail and ask you what you want to do:
126
127
127
128
[source,console]
128
-
-----
129
+
----
129
130
$ git am 0001-seeing-if-this-helps-the-gem.patch
130
131
Applying: seeing if this helps the gem
131
132
error: patch failed: ticgit.gemspec:1
@@ -134,48 +135,48 @@ Patch failed at 0001.
134
135
When you have resolved this problem run "git am --resolved".
135
136
If you would prefer to skip this patch, instead run "git am --skip".
136
137
To restore the original branch and stop patching run "git am --abort".
137
-
-----
138
+
----
138
139
139
140
This command puts conflict markers in any files it has issues with, much like a conflicted merge or rebase operation.
140
141
You solve this issue much the same way – edit the file to resolve the conflict, stage the new file, and then run `git am --resolved` to continue to the next patch:
141
142
142
143
[source,console]
143
-
-----
144
+
----
144
145
$ (fix the file)
145
146
$ git add ticgit.gemspec
146
147
$ git am --resolved
147
148
Applying: seeing if this helps the gem
148
-
-----
149
+
----
149
150
150
151
If you want Git to try a bit more intelligently to resolve the conflict, you can pass a `-3` option to it, which makes Git attempt a three-way merge.
151
152
This option isn't on by default because it doesn't work if the commit the patch says it was based on isn't in your repository.
152
153
If you do have that commit – if the patch was based on a public commit – then the `-3` option is generally much smarter about applying a conflicting patch:
153
154
154
155
[source,console]
155
-
-----
156
+
----
156
157
$ git am -3 0001-seeing-if-this-helps-the-gem.patch
157
158
Applying: seeing if this helps the gem
158
159
error: patch failed: ticgit.gemspec:1
159
160
error: ticgit.gemspec: patch does not apply
160
161
Using index info to reconstruct a base tree...
161
162
Falling back to patching base and 3-way merge...
162
163
No changes -- Patch already applied.
163
-
-----
164
+
----
164
165
165
166
In this case, this patch had already been applied.
166
167
Without the `-3` option, it looks like a conflict.
167
168
168
169
If you're applying a number of patches from an mbox, you can also run the `am` command in interactive mode, which stops at each patch it finds and asks if you want to apply it:
169
170
170
171
[source,console]
171
-
-----
172
+
----
172
173
$ git am -3 -i mbox
173
174
Commit Body is:
174
175
--------------------------
175
176
seeing if this helps the gem
176
177
--------------------------
177
178
Apply? [y]es/[n]o/[e]dit/[v]iew patch/[a]ccept all
178
-
-----
179
+
----
179
180
180
181
This is nice if you have a number of patches saved, because you can view the patch first if you don't remember what it is, or not apply the patch if you've already done so.
181
182
@@ -190,11 +191,11 @@ If your contribution came from a Git user who set up their own repository, pushe
190
191
For instance, if Jessica sends you an email saying that she has a great new feature in the `ruby-client` branch of her repository, you can test it by adding the remote and checking out that branch locally:
If she emails you again later with another branch containing another great feature, you can fetch and check out because you already have the remote setup.
200
201
@@ -210,12 +211,12 @@ If you aren't working with a person consistently but still want to pull from the
210
211
This does a one-time pull and doesn't save the URL as a remote reference:
211
212
212
213
[source,console]
213
-
-----
214
+
----
214
215
$ git pull https://github.com/onetimeguy/project
215
216
From https://github.com/onetimeguy/project
216
217
* branch HEAD -> FETCH_HEAD
217
218
Merge made by recursive.
218
-
-----
219
+
----
219
220
220
221
[[_what_is_introduced]]
221
222
==== Determining What Is Introduced
@@ -231,7 +232,7 @@ This does the same thing as the `master..contrib` format that we used earlier.
231
232
For example, if your contributor sends you two patches and you create a branch called `contrib` and applied those patches there, you can run this:
To see what changes each commit introduces, remember that you can pass the `-p` option to `git log` and it will append the diff introduced to each commit.
250
251
251
252
To see a full diff of what would happen if you were to merge this topic branch with another branch, you may have to use a weird trick to get the correct results.
252
253
You may think to run this:
253
254
254
255
[source,console]
255
-
-----
256
+
----
256
257
$ git diff master
257
-
-----
258
+
----
258
259
259
260
This command gives you a diff, but it may be misleading.
260
261
If your `master` branch has moved forward since you created the topic branch from it, then you'll get seemingly strange results.
@@ -269,19 +270,19 @@ You do that by having Git compare the last commit on your topic branch with the
269
270
Technically, you can do that by explicitly figuring out the common ancestor and then running your diff on it:
270
271
271
272
[source,console]
272
-
-----
273
+
----
273
274
$ git merge-base contrib master
274
275
36c7dba2c95e6bbb78dfa822519ecfec6e1ca649
275
276
$ git diff 36c7db
276
-
-----
277
+
----
277
278
278
279
However, that isn't convenient, so Git provides another shorthand for doing the same thing: the triple-dot syntax.
279
280
In the context of the `diff` command, you can put three periods after another branch to do a `diff` between the last commit of the branch you're on and its common ancestor with another branch:
280
281
281
282
[source,console]
282
-
-----
283
+
----
283
284
$ git diff master...contrib
284
-
-----
285
+
----
285
286
286
287
This command shows you only the work your current topic branch has introduced since its common ancestor with master.
287
288
That is a very useful syntax to remember.
@@ -376,12 +377,12 @@ image::images/rebasing-1.png[Example history before a cherry-pick.]
376
377
If you want to pull commit `e43a6` into your master branch, you can run
If you do sign your tags, you may have the problem of distributing the public PGP key used to sign your tags.
434
435
The maintainer of the Git project has solved this issue by including their public key as a blob in the repository and then adding a tag that points directly to that content.
435
436
To do this, you can figure out which key you want by running `gpg --list-keys`:
sub 2048g/45D02282 2009-02-09 [expires: 2010-02-09]
445
-
-----
446
+
----
446
447
447
448
Then, you can directly import the key into the Git database by exporting it and piping that through `git hash-object`, which writes a new blob with those contents into Git and gives you back the SHA-1 of the blob:
448
449
449
450
[source,console]
450
-
-----
451
+
----
451
452
$ gpg -a --export F721C45A | git hash-object -w --stdin
452
453
659ef797d181633c87ec71ac3f9ba29fe5775b92
453
-
-----
454
+
----
454
455
455
456
Now that you have the contents of your key in Git, you can create a tag that points directly to it by specifying the new SHA-1 value that the `hash-object` command gave you:
456
457
457
458
[source,console]
458
-
-----
459
+
----
459
460
$ git tag -a maintainer-pgp-pub 659ef797d181633c87ec71ac3f9ba29fe5775b92
460
-
-----
461
+
----
461
462
462
463
If you run `git push --tags`, the `maintainer-pgp-pub` tag will be shared with everyone.
463
464
If anyone wants to verify a tag, they can directly import your PGP key by pulling the blob directly out of the database and importing it into GPG:
464
465
465
466
[source,console]
466
-
-----
467
+
----
467
468
$ git show maintainer-pgp-pub | gpg --import
468
-
-----
469
+
----
469
470
470
471
They can use that key to verify all your signed tags.
471
472
Also, if you include instructions in the tag message, running `git show <tag>` will let you give the end user more specific instructions about tag verification.
@@ -478,10 +479,10 @@ Because Git doesn't have monotonically increasing numbers like 'v123' or the equ
478
479
Git gives you the name of the nearest tag with the number of commits on top of that tag and a partial SHA-1 value of the commit you're describing:
479
480
480
481
[source,console]
481
-
-----
482
+
----
482
483
$ git describe master
483
484
v1.6.2-rc1-20-g8c5b85c
484
-
-----
485
+
----
485
486
486
487
This way, you can export a snapshot or build and name it something understandable to people.
487
488
In fact, if you build Git from source code cloned from the Git repository, `git --version` gives you something that looks like this.
@@ -500,19 +501,19 @@ One of the things you'll want to do is create an archive of the latest snapshot
You now have a nice tarball and a zip archive of your project release that you can upload to your website or email to people.
518
519
@@ -525,7 +526,7 @@ A nice way of quickly getting a sort of changelog of what has been added to your
525
526
It summarizes all the commits in the range you give it; for example, the following gives you a summary of all the commits since your last release, if your last release was named v1.0.1:
526
527
527
528
[source,console]
528
-
-----
529
+
----
529
530
$ git shortlog --no-merges master --not v1.0.1
530
531
Chris Wanstrath (8):
531
532
Add support for annotated tags to Grit::Tag
@@ -540,6 +541,6 @@ Tom Preston-Werner (4):
540
541
dynamic version method
541
542
Version bump to 1.0.2
542
543
Regenerated gemspec for version 1.0.2
543
-
-----
544
+
----
544
545
545
546
You get a clean summary of all the commits since v1.0.1, grouped by author, that you can email to your list.
0 commit comments