LoginSignup
5
4

More than 1 year has passed since last update.

【Git】git add -p 実行時の「e」コマンドの使い方とは?

Posted at

はじめに

git add -p を実行した時の e コマンドの使い方で戸惑ったので、記事を書きたいと思います。

添付の画像で示している e の部分です。

スクリーンショット 2022-09-18 8.20.34.png

他のgit add -p を実行した時のコマンドの説明に関しては、以下の記事をご確認下さい。

git add -p とは?

Git - git-add Documentation からの引用

-p
--patch
Interactively choose hunks of patch between the index and the work tree and add them to the index. This gives the user a chance to review the difference before adding modified contents to the index.

This effectively runs add --interactive, but bypasses the initial command menu and directly jumps to the patch subcommand. See “Interactive mode” for details.

「ファイルごと」ではなく「行ごと」に作業ディレクトリからステージングエリアにファイルを上げることができるコマンドになります。

git add -p 実行時の e コマンドの使い方

e コマンドの実行

git add -p を実行後に e コマンドを実行します。

% git add -p
diff --git a/README.md b/README.md
index 2b6b5c7..ea918fb 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@ The code to create the following resources.
 - EC2 Instance(AmazonLinux2)
 - VPC
 - S3
+- Security Group

 This code was created for the purpose of being able to SSH into Amazon Linux 2.
 <br>
(1/1) Stage this hunk [y,n,q,a,d,e,?]? e

e コマンドを実行すると、以下のように表示されます。

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -3,7 +3,8 @@
 The code to create the following resources.

 - EC2 Instance(AmazonLinux2)
-- VPC
+- S3
+- Security Group

 This code was created for the purpose of being able to SSH into Amazon Linux 2.
 <br>
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
# If the patch applies cleanly, the edited hunk will immediately be marked for staging.
# If it does not apply cleanly, you will be given an opportunity to
# edit again.  If all lines of the hunk are removed, then the edit is
# aborted and the hunk is left unchanged.

削除対象の行をステージングエリアに追加したくない場合

- となっている行が、削除対象の行になっております。

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -3,7 +3,8 @@
 The code to create the following resources.

 - EC2 Instance(AmazonLinux2)
-- VPC ← これ
+- S3
+- Security Group

この - を、 (空欄)に置き換えます。
(空欄に置き換えないと、エラーになります。)

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -3,7 +3,8 @@
 The code to create the following resources.

 - EC2 Instance(AmazonLinux2)
 - VPC ← これ
+- S3
+- Security Group

ファイルの下に以下のような説明がありますが、この通りになります。

# To remove '-' lines, make them ' ' lines (context).

追加対象の行をステージングエリアに追加したくない場合

+ となっている行が、追加対象の行になっております。

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -3,7 +3,8 @@
 The code to create the following resources.

 - EC2 Instance(AmazonLinux2)
-- VPC 
+- S3 ← これ
+- Security Group

この + の行を削除します。

# Manual hunk edit mode -- see bottom for a quick guide.
@@ -3,7 +3,8 @@
 The code to create the following resources.

 - EC2 Instance(AmazonLinux2)
 - VPC
+- Security Group

ファイルの下に以下のような説明がありますが、この通りになります。

# To remove '+' lines, delete them.

# から始まる行

# から始まる行は削除されます。

# Manual hunk edit mode -- see bottom for a quick guide. ← これ
@@ -3,7 +3,8 @@
 The code to create the following resources.

 - EC2 Instance(AmazonLinux2)
-- VPC 
+- S3
+- Security Group

ファイルの下に以下のような説明がありますが、この通りになります。

# Lines starting with # will be removed.

さいごに

「ちゃんと説明書きを読め!」 という言葉に尽きますが、同じような部分で迷う人が1人でも減ることを祈るばかりです。

参考

5
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
4