Git: Difference between revisions
From Mintarc Forge
No edit summary |
No edit summary |
||
| Line 134: | Line 134: | ||
===ではここで=== | ===ではここで=== | ||
newFileを開いて「消される運命にある一行」と入力し,改行して上書き保存して×とじ<br/> | newFileを開いて「消される運命にある一行」と入力し,改行して上書き保存して×とじ<br/> | ||
ステージングしてコミットする前に、そもそも前回自分が書き込んだ内容と、現在変更した内容との<span style="font-size:24px;">変更点(=差分)</span>を確認してみよう | |||
<pre style="border: 1px solid #ccd1d9; background-color: #f8f9fa; padding: 12px; border-radius: 4px; color: #333; font-family: monospace;"> | |||
<pre> | |||
$ git diff | $ git diff | ||
diff --git a/newFile.txt b/newFile.txt | diff --git a/newFile.txt b/newFile.txt | ||
| Line 149: | Line 145: | ||
新しい行を追加 | 新しい行を追加 | ||
+消される運命にある一行 | +消される運命にある一行 | ||
</pre> | </pre><br/> | ||
$ git restore newFile.txt | $ git restore newFile.txt | ||
Revision as of 00:16, 3 June 2026
<< ひよっこ書庫
Gitに触れてみた記録
2026/05/21 Git bash
参考にした動画:https://youtu.be/cyOTQzI2AFU?si=CJSALJrGVrLPr3co
VCcode、Git bashをインストールした。
あらかじめ
デスクトップにバージョン管理したいファイル(今回は「GitTest」)を作成しておいた
もちろんファイルの場所はどこでも可
ユーザー名設定(初期設定)
$ git config --grobal user.name '任意の名前'
メールアドレス登録設定(初期設定)
$ git config --grobal user.email メールアドレス
GitTestへ移動(ディレクトリ移動)
$ cd /c/Users/makko/Desktop/GitTest
バージョンしていくファイルを作成
GitTestフォルダ直下になにかしらのファイルを作成
今回は「newFile」という名前のテキストファイルにした
テキストファイル中に「これは新しいファイルです」と入力し、改行して上書き保存して×とじ
リポジトリに登録への道①~ワークツリーに登録~
ワークツリー → ステージング → リポジトリ
「リポジトリ」に登録できたらバージョン管理ができる
$ git init
「この GitTest というファイルの中身をバージョン管理していきますよ」をこのコマンドにより知らせた。
実行したことで GitTest フォルダの中に .git という隠しフォルダが作られた。
(隠しフォルダも表示されるようにあらかじめ設定したので、今回は見えている)
この .git フォルダの中には実際にバージョン管理されているファイルの記録や変更点の記録が保存されていく。
※まだこの時点ではバージョン管理されていない
隠しフォルダも見えるようにする設定
hさhdjhkdhsdhjか
2026/05/26 Git bash
参考にした動画:https://youtu.be/cyOTQzI2AFU?si=CJSALJrGVrLPr3co
5/21の続き。
まずは GitTest フォルダに移動
$ cd /c/Users/makko/Desktop/GitTest
リポジトリに登録への道②~newFileをステージングに追加~
リポジトリに登録への道①ではまだ、ワークツリーに登録された状態
ワークツリー → ステージング → リポジトリ
「リポジトリ」に登録できたらバージョン管理ができる
$ git add newFile.txt
リポジトリに登録への道③~リポジトリに追加~
リポジトリに登録への道②ではまだ、ワークツリーに登録された状態
ワークツリー → ステージング → リポジトリ
「リポジトリ」に登録できたらバージョン管理ができる
$ git commit -m "初めてのコミット"
-mのあとはどういう変更点を加えたのかわかるようにコメントを書く
※これでバージョン管理ができる状態になった!
nweFileに新しい行を追加してみる
テキストファイル「newFile」を開いて、
「新しい行を追加」と入力し、改行して上書き保存して×とじ。
git statusコマンドで状態を確認してみると...
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: newFile.txt
no changes added to commit (use "git add" and/or "git commit -a")
「modified」と出てきているので
newFileに対して何から変更が加わってるのが確認できる。
ここで再度ステージング&リポジトリに書き込みを行う
ステージング
$ git add .
リポジトリに書き込む(=コミットする)
$ git commit -m "新しい行の追加"
これでnewFileに対する変更をさらに書き加えることに成功した。
これまでのコミット(変更点)を確認する
「git log」コマンドでこれまでどのようなコミットをしてきたのか確認する
$ git log
commit c049436e84acc752b875fa98a629467d0b6ec321 (HEAD -> master)
Author: makoto <araheu15akim@gmail.com>
Date: Tue May 26 08:02:50 2026 +0900
新しい行の追加
commit 4aa851f08a6abf5ae22e956b377caaebac437166
Author: makoto <araheu15akim@gmail.com>
Date: Tue May 26 08:00:48 2026 +0900
初めてのコミット
ではここで
newFileを開いて「消される運命にある一行」と入力し,改行して上書き保存して×とじ
ステージングしてコミットする前に、そもそも前回自分が書き込んだ内容と、現在変更した内容との変更点(=差分)を確認してみよう
$ git diff diff --git a/newFile.txt b/newFile.txt index 1c90f50..7529f41 100644 --- a/newFile.txt +++ b/newFile.txt @@ -1,2 +1,3 @@ これは新しいファイルです 新しい行を追加 +消される運命にある一行
$ git restore newFile.txt
$ git branch * master
$ git branch feature1
$ git branch feature2
$ git branch feature1 feature2 * master
$ git switch feature1
$ git branch * feature1 feature2 master
git add .
$ git commit -m "feature1の変更点"
$ git switch feature2
git add .
$ git commit -m "feature2の変更点"
$ git switch master
$ git merge feature1
$ git merge feature1 Updating c049436..86960d3 Fast-forward newFile.txt | 1 + 1 file changed, 1 insertion(+)
$ git merge feature2
$ git merge feature2 Auto-merging newFile.txt CONFLICT (content): Merge conflict in newFile.txt Automatic merge failed; fix conflicts and then commit the result.
git add .
$ git commit -m "完成"
$ git branch feature1 feature2 * master
$ git branch -d feature1
$ git branch -d feature2
$ git branch * master
<< ひよっこ書庫
