LoginSignup
0
0

More than 1 year has passed since last update.

履歴の中での違いを見る

Posted at

履歴の中での違いを見る

git diff コミット1 コミット2

2つのコミットの差を表示する。
コミットのハッシュ値やHEADで指定する

コミットのハッシュ値を調べるにはgit logで調べる。

**********@mbp training % git log
commit コミットのハッシュ値(HEAD -> master)
Author: mhyodo <n-bv-10dor-.ra3@mineo.jp>
Date:   Sun Jun 12 16:39:42 2022 +0900

    演習課題 hello.txtを新しくコミットする

commit ************************
Author: mhyodo <n-bv-10dor-.ra3@mineo.jp>
Date:   Sun Jun 12 16:37:50 2022 +0900

    演習課題 RAEDME.mdを修正

commit ************************
Author: mhyodo <n-bv-10dor-.ra3@mineo.jp>
Date:   Tue Jun 7 14:27:10 2022 +0900

    this is test commit.

commit ************************
Author: mhyodo <n-bv-10dor-.ra3@mineo.jp>
Date:   Wed Jun 1 12:08:46 2022 +0900

    練習用アプリを作成 rails new -B -T -J -d mysql -C .

ハッシュ値は長いので最初の6文字ぐらいでいい。

************@mbp training % git diff ****** ******
diff --git a/README.md b/README.md
index 70d07f1..7db80e4 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,24 @@
-This is a test project for Git.
-Contents:
-* hello.txt
+# README
+
+This README would normally document whatever steps are necessary to get the
+application up and running.
+
+Things you may want to cover:
+
+* Ruby version
+
+* System dependencies
+
+* Configuration
+
+* Database creation
+
+* Database initialization
+
+* How to run the test suite
+
+* Services (job queues, cache servers, search engines, etc.)
+
+* Deployment instructions
+
+* ...
diff --git a/hello.txt b/hello.txt
deleted file mode 100644
index 10ddd6d..0000000
--- a/hello.txt
+++ /dev/null
@@ -1 +0,0 @@
-Hello!
***********@mbp training % git diff HEAD^^^ HEAD
diff --git a/README.md b/README.md
index 7db80e4..70d07f1 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,3 @@
-# README
-
-This README would normally document whatever steps are necessary to get the
-application up and running.
-
-Things you may want to cover:
-
-* Ruby version
-
-* System dependencies
-
-* Configuration
-
-* Database creation
-
-* Database initialization
-
-* How to run the test suite
-
-* Services (job queues, cache servers, search engines, etc.)
-
-* Deployment instructions
-
-* ...
+This is a test project for Git.
+Contents:
+* hello.txt
diff --git a/hello.txt b/hello.txt
new file mode 100644
index 0000000..10ddd6d
--- /dev/null
+++ b/hello.txt
@@ -0,0 +1 @@
+Hello!

^をつけるごとにHEADのひとつ前のコミットを指定できる

**********@mbp training % git diff HEAD~3 HEAD
diff --git a/README.md b/README.md
index 7db80e4..70d07f1 100644
--- a/README.md
+++ b/README.md
@@ -1,24 +1,3 @@
-# README
-
-This README would normally document whatever steps are necessary to get the
-application up and running.
-
-Things you may want to cover:
-
-* Ruby version
-
-* System dependencies
-
-* Configuration
-
-* Database creation
-
-* Database initialization
-
-* How to run the test suite
-
-* Services (job queues, cache servers, search engines, etc.)
-
-* Deployment instructions
-
-* ...
+This is a test project for Git.
+Contents:
+* hello.txt
diff --git a/hello.txt b/hello.txt
new file mode 100644
index 0000000..10ddd6d
--- /dev/null
+++ b/hello.txt
@@ -0,0 +1 @@
+Hello!

git diff HEAD~3 HEAD~数字で数字前のコミットを指定できる。
READMD.mdが削除と追加が確認される。
hello.txtではHello!という文が追加されている。

git diff コミット1 コミット2 --ファイル

ファイルを指定することで2つのコミット間の指定ファイルの違いを調べることができる。

出典 わかるGit (冨永和人 著)

0
0
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
0
0