gitのメモ
gitの使い方メモ
◎ファイルを編集した時(クライアントマシン)
$ git add -A
$ git status
$ git commit -m 'コメントを書く'
?git add -A
コミットするファイルを指定
編集したファイルを全て指定、個別にファイル名を指定もできる
<例>
git add [file1.php] [file2.php] [file3.php]
?git status
git add コマンドで追加されたコミットするファイルを表示
?git commit -m '[コメントを書く]'
編集した箇所をコミットする、リポジトリに反映する
◎コミットログを表示
$ git log
◎ファイルをgitの管理下からはずす方法
/app/config/ ディレクトリ以下を外す場合
$ git rm -r --cached /app/config/
$ echo app/config/ >> .gitignore
$ git commit -m '[コメント]'
◎ローカルのリポジトリをリモートリポジトリにcommitする
$ git remote add origin ssh://root@219.94.228.223/home/git/freesic.git
$ git push origin master
root@219.94.228.223's password: [パスワードを入力]
※ローカルで行ったcommitが全て反映される
※管理下から外したcommitも反映される
◎本番環境にファイルを反映する
?本番環境にcloneを作成する
$ mkdir /home/test
$ cd /home/test/
$ git init
$ git clone /home/git/freesic.git/
例> git clone [クローン作成元のリポジトリ]
?ローカルからリモートリポジトリにpush
?サーバ側でpull を実行
$ cd /home/test/freesic
$ git pull
コミットしたファイルが反映される
?上記の作業を自動化する
リモートリポジトリのhooks/post-update.sample を修正する
$ cp post-update.sample post-update
$ vim post-update
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".
(cd /home/gittest/freesic && git --git-dir=.git pull origin master) ←追加する行
exec git update-server-info
※/home/gittest/freesicはcloneで作成