Git(応用) - user000422/0 GitHub Wiki

Git hooks

Gitのアクションをフックしスクリプトを自動実行する。

Git hooksスクリプトディレクトリ .git/hooks ファイル名の「.sample」を外すとスクリプトとして機能します。 用意されているものと、標準なのに用意されていないものがあります。

スクリプト フック
post-merge git merge git pull
# post-merge を作成。
touch .git/hooks/post-merge
chmod 775 .git/hooks/post-merge
# post-merge 例 テキストファイルの所有者を変更
#!/usr/bin/sh
chown apache:apache /sample/sample.txt

スクールで使っていたコマンド

# git clone
cd フォルダ位置パス # アップロード等で使う階層より1つ上
git clone https://github.com/アカウント名/リポジトリ名

# 連携
cd フォルダ位置パス
git config user.name "ユーザー名"
git config user.email "メールアドレス"

# リポジトリへアップロード
# ローカルフォルダ .metadata を削除してからアップロード
cd フォルダ位置パス
git add --all
git commit -m "コメント"
git push

# エラーが出た場合
git remote set-url origin http://アカウント名:パスワード@github.com/アカウント名/test

# チーム開発でcloneするときの
git clone https://github.com/ユーザー名/リポジトリ名

ファイル権限変更差分を無視 ファイルの権限変更を差分として判定してほしくない場合に。

# 設定確認(デフォルトは「true」)
git config --get --local core.filemode

# 変更(Falseに変更)
git config --local core.fileMode false

マージ後、そのマージを取り消したくなった

git revert -m 1 コミットID

ローカルリポジトリを作成し、リモートへ登録する方法(途中)

cd フォルダ位置パス
git init
# ここでソースを配置
git add .
git commit -m "コミットメッセージ"
git checkout --orphan "ブランチ名"
git add .
git commit -m "コミットメッセージ"
git remote add origin https://sample.com/userName/repositorieName.git
git push -u origin "ブランチ名"

リポジトリを複製する

# 複製先のリポジトリを作成しておく
# ローカルに作業用フォルダを作成
# コマンドプロンプトで作業用フォルダに移動
cd sample_dir

# 複製元をミラーcloneする
git clone --mirror https://[複製元リポジトリ]

# 複製したGitに移動
cd [リポジトリ名].git

# 複製先のリポジトリにpush
git push --mirror https://[複製先リポジトリ]

# 作業用フォルダを削除して完了