LoginSignup
4
5

More than 3 years have passed since last update.

『独習Git』4章メモ

Last updated at Posted at 2017-11-09

扱うコマンド

  • git init
  • git status
  • git add
  • git commit -m
  • git log
  • git ls-files

コマンド例

★空のディレクトリ(repo)上で `git init`コマンドを実施し、リポジトリが作成される(.gitディレクトリができる) 
ubuntu# git init
Initialized empty Git repository in /home/kure/repo/.git/
ubuntu# ls
ubuntu# ls -laht
合計 12K
drwxr-xr-x  7 root root 4.0K Nov  9 23:21 .git
drwxr-xr-x  3 root root 4.0K Nov  9 23:21 .
drwxrwxr-x 26 kure kure 4.0K Nov  9 23:21 ..

★ この時点でgit logしてもブランチにコミット履歴が無いからか、怒られる
ubuntu# git log
fatal: your current branch 'master' does not have any commits yet

★この時点でgit ls-filesしてもまだ何もGitに追跡されてないので、何も表示されない
ubuntu# git ls-files
★ファイル作成
ubuntu# touch file1

★git statusで見ると、追跡されてないファイル(今作ったfile1)が見える
ubuntu# git status
On branch master

最初のコミット

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        file1

★git addで追跡を開始するとls-filesでも見えるようになり、git statusの結果もnew fileとして表示される
ubuntu# git add file1
ubuntu# git ls-files
file1
ubuntu# git status
On branch master

最初のコミット

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

        new file:   file1
★コミットする
ubuntu# git commit -m "first"
[master (root-commit) ab05ab6] first
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1
★statusで見てもコミットしたばかりなので、他にコミットするものが無い、というメッセージが表示される
ubuntu# git status
On branch master
nothing to commit, working directory clean
★git logで見るとコミットのログが表示される
commit ab05ab6618fccddb3155061b246600a20a1b6f21
Author: root <@gmail.com>
Date:   Thu Nov 9 23:23:08 2017 +0900

    first
4
5
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
4
5