ユーザ用ツール

サイト用ツール


git:1st_step

1st_step

動作イメージ

基本的な使い方

ディレクトリ作成

[root@a3 tmp]# mkdir test.git
[root@a3 tmp]# cd test.git/

git 初期化

[root@a3 test.git]# git init
Initialized empty Git repository in /tmp/test.git/.git/

テストデータ作成

[root@a3 test.git]# echo "This is test page" > test.html
[root@a3 test.git]# cat test.html 
This is test page

git 状態確認
gitの管理対象外(Untracked files)のファイルとして「test.html」が確認できる

[root@a3 test.git]# git status
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       test.html
nothing added to commit but untracked files present (use "git add" to track)

「test.html」をgitの管理下に含める

[root@a3 test.git]# git add test.html

git 状態確認
gitの管理下・コミット候補(Changes to be committed)のファイルとして「test.html」が確認できる

[root@a3 test.git]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   test.html
#

git コミットメッセージをつけてコミット
ユーザの設定をしていないので、ログインユーザで自動的に設定

[root@a3 test.git]# git commit -m "first commit"
[master (root-commit) 69c480c] first commit
 Committer: root <root@a3.clown.jp>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 test.html

ユーザの設定

[root@a3 test.git]# git config --global user.name "taro"
[root@a3 test.git]# git config --global user.email taro@mail.com
[root@a3 test.git]# git config --global --list
user.name=taro
user.email=taro@mail.com

ユーザの設定は実行するたびに上書きされる

[root@a3 test.git]# git config --global user.name "hanako"
[root@a3 test.git]# git config --global user.email hanako@mail.com
[root@a3 test.git]# git config --global --list
user.name=hanako
user.email=hanako@mail.com

git コミットログを確認する

[root@a3 test.git]# git log
commit 4a6788b7b2c5e9df152bc90e6b17728aab9acf0f
Author: hanako <hanako@mail.com>
Date:   Tue Feb 5 10:18:30 2013 +0900

    this is 2nd commit

commit 69c480cef8a7388a238a7570bbe2b2cfd3b3ca24
Author: root <root@a3.clown.jp>
Date:   Tue Feb 5 10:06:11 2013 +0900

    first commit

GitHubからとってくることも可能

例えば、nginxの最新ソースを取得。

[root@a3 tmp]# mkdir nginx.git
[root@a3 tmp]# cd nginx.git/
[root@a3 nginx.git]# git clone git://github.com/git-mirror/nginx.git
Cloning into 'nginx'...
remote: Counting objects: 41740, done.
remote: Compressing objects: 100% (9346/9346), done.
remote: Total 41740 (delta 32018), reused 41452 (delta 31742)
Receiving objects: 100% (41740/41740), 6.44 MiB | 1.34 MiB/s, done.
Resolving deltas: 100% (32018/32018), done.
[root@a3 nginx.git]#
git/1st_step.txt · 最終更新: 2016/03/28 05:57 by clownclown

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki