LoginSignup
1
0

More than 1 year has passed since last update.

Gitまとめ

Posted at

///
Gitはスナップショットを記録する。
Gitはデータをバージョンとしてそのまま保存する。(差分ではなく、そのまま保存する)
Gitは以前の状態に戻せる。(コミットを辿ることで以前のコミットに戻せる)
///

///
ワークツリー(自分の作業場) ①⇨ ローカルリポジトリ(自分のパソコンの履歴データ) ⇨ リモートリポジトリ(Github)

①まずはローカルに差分ではなく、全体のスナップショットとして記録する。

他人のデータを取得する
リモートリポジトリ(Github)⇨ ローカルリポジトリ ⇨ ワークツリー

ローカルは3つのエリアからできている
ワークツリー git add⇨ ①ステージ(スナップショットをコミットする変更を準備)git commit⇨ ローカルリポジトリ(スナップショットを記録する)

①ステージはなぜあるのか
変更したファイルだけをステージに追加したいから。
いらないファイルと分けたい

///

///
🔥ワークツリー index.html //git add//⇨ 🔥リポジトリ index.htmlのファイル内容を圧縮する//git add// ⇨ 🔥ステージ index.html 圧縮ファイルA //git commit// ⇨ 🔥リポジトリ ツリー1 圧縮ファイル コミット1(ツリー1、作成者、日付、コミットメッセージ)
///

Gitの本質はデータを圧縮してスナップショットとして保存すること
コミットを辿ることで以前のファイルをgetすることができる。

//ローカルリポジトリを作成する
git init
このコマンドで.gitデいレクトリを作成する
.gitの中にgitで必要なものは一式揃っている

% mkdir git_tutorial(ファイル作成)
% cd git_tutorial 
git_tutorial % git init
Initialized empty Git repository in /
git_tutorial % ls -a
.	..	.git
git_tutorial % ls .git/
HEAD		description	info		refs
config		hooks		objects

///
git clone
gitリポジトリのファイルをgetする。
下のコマンドがgit cloneの一連の流れ

 % git clone https://github.com/microsoft/vscode.git
Cloning into 'vscode'...
remote: Enumerating objects: 1246200, done.
remote: Total 1246200 (delta 0), reused 0 (delta 0), pack-reused 1246200
Receiving objects: 100% (1246200/1246200), 463.28 MiB | 6.77 MiB/s, done.
Resolving deltas: 100% (892372/892372), done.
 git_tutorial % ls -a
.	..	.git	vscode
 git_tutorial % cd vscode
 vscode % ls -a
.			.mailmap		extensions
..			.mention-bot		gulpfile.js
.devcontainer		.vscode			package.json
.editorconfig		.yarnrc			product.json
.eslintignore		CONTRIBUTING.md		remote
.eslintrc.json		LICENSE.txt		resources
.git			README.md		scripts
.git-blame-ignore	SECURITY.md		src
.gitattributes		ThirdPartyNotices.txt	test
.github			build			tsfmt.json
.gitignore		cglicenses.json		yarn.lock
.lsifrc.json		cgmanifest.json

///

///

変更を記録すること commit(ステージからリポジトリに保存すること)
ツリーファイルとコミットファイルが作製される。
・ツリーファイル バージョンの履歴を辿れる
・コミットファイル コミットした内容を見れる
git commit -m メッセージをつける
git statusで状況を確認することもおすすめ

git_tutorial % git status        
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	modified:   index.html
git_tutorial % git commit -m thirdcommit 
[master 009c55f] thirdcommit
 1 file changed, 2 insertions(+), 1 deletion(-)
git_tutorial % git status
On branch master
nothing to commit, working tree clean

///

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