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
Copy file name to clipboardExpand all lines: book/07-git-tools/sections/interactive-staging.asc
+11-12Lines changed: 11 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
1
[[_interactive_staging]]
2
2
=== Interactive Staging
3
3
4
-
Git comes with a couple of scripts that make some command-line tasks easier.
5
-
Here, you’ll look at a few interactive commands that can help you easily craft your commits to include only certain combinations and parts of files.
6
-
These tools are very helpful if you modify a bunch of files and then decide that you want those changes to be in several focused commits rather than one big messy commit.
4
+
In this section, you’ll look at a few interactive Git commands that can help you easily craft your commits to include only certain combinations and parts of files.
5
+
These tools are helpful if you modify a number of files and then decide that you want those changes to be in several focused commits rather than one big messy commit.
7
6
This way, you can make sure your commits are logically separate changesets and can be easily reviewed by the developers working with you.
8
-
If you run `git add` with the `-i` or `--interactive` option, Git goes into an interactive shell mode, displaying something like this:
7
+
8
+
If you run `git add` with the `-i` or `--interactive` option, Git enters an interactive shell mode, displaying something like this:
9
9
10
10
[source,console]
11
11
----
@@ -21,15 +21,14 @@ $ git add -i
21
21
What now>
22
22
----
23
23
24
-
You can see that this command shows you a much different view of your staging area – basically the same information you get with `git status` but a bit more succinct and informative.
24
+
You can see that this command shows you a much different view of your staging area than you're probably used to -- basically, the same information you get with `git status` but a bit more succinct and informative.
25
25
It lists the changes you’ve staged on the left and unstaged changes on the right.
26
26
27
-
After this comes a Commands section.
28
-
Here you can do a number of things, including staging files, unstaging files, staging parts of files, adding untracked files, and seeing diffs of what has been staged.
27
+
After this comes a ``Commands'' section, which allows you to do a number of things like staging and unstaging files, staging parts of files, adding untracked files, and displaying diffs of what has been staged.
29
28
30
29
==== Staging and Unstaging Files
31
30
32
-
If you type `2` or `u` at the `What now>` prompt, the script prompts you for which files you want to stage:
31
+
If you type `2` or `u` at the `What now>` prompt, you're prompted for which files you want to stage:
33
32
34
33
[source,console]
35
34
----
@@ -138,9 +137,9 @@ With these basic commands, you can use the interactive add mode to deal with you
138
137
139
138
==== Staging Patches
140
139
141
-
It’s also possible for Git to stage certain parts of files and not the rest.
140
+
It’s also possible for Git to stage certain _parts_ of files and not the rest.
142
141
For example, if you make two changes to your `simplegit.rb` file and want to stage one of them and not the other, doing so is very easy in Git.
143
-
From the interactive prompt, type `5` or `p` (for patch).
142
+
From the same interactive prompt explained in the previous section, type `5` or `p` (for patch).
144
143
Git will ask you which files you would like to partially stage; then, for each section of the selected files, it will display hunks of the file diff and ask if you would like to stage them, one by one:
145
144
146
145
[source,console]
@@ -199,7 +198,7 @@ It shows you that a couple of lines are staged and a couple are unstaged.
199
198
You’ve partially staged this file.
200
199
At this point, you can exit the interactive adding script and run `git commit` to commit the partially staged files.
201
200
202
-
You also don’t need to be in interactive add mode to do the partial-file staging – you can start the same script by using `git add -p` or `git add --patch` on the command line.
201
+
You also don’t need to be in interactive add mode to do the partial-file staging -- you can start the same script by using `git add -p` or `git add --patch` on the command line.
203
202
204
-
Furthermore, you can use patch mode for partially resetting files with the `reset --patch` command, for checking out parts of files with the `checkout --patch` command and for stashing parts of files with the `stash save --patch` command.
203
+
Furthermore, you can use patch mode for partially resetting files with the `git reset --patch` command, for checking out parts of files with the `git checkout --patch` command and for stashing parts of files with the `git stash save --patch` command.
205
204
We'll go into more details on each of these as we get to more advanced usages of these commands.
0 commit comments