Git
January 13, 2020
設定
.gitconfig に記述する.
$ git config --global user.name "Daisuke Kobayashi"
$ git config --global user.email "username@example.com"
$ git config --global http.proxy http://*.*.*.*:8080
$ git config --global core.autocrlf false
$ git config --global core.safecrlf true
https 時に認証情報を保存する.
$ git config --global credential.helper cache
$ git config --global credential.helper 'cache --timeout=3600'
gitignore
.gitignore に記述する.
# シャープから始まる行はコメント
# ディレクトリを指定する場合には最後にスラッシュ(/)をつける
# 感嘆符(!)はパターンを反転
操作
ファイルの変更取り消し
$ git checkout HEAD -- file.txt
add の取り消し
$ git reset HEAD foo.txt
直前のコミットログの修正
$ git commit --amend -m "hogehoge"
$ git push -f [repository] [branch]
n個以上前のコミットログの修正
git rebase -i HEAD~n
- エディタが開くのでログを変更したいコミットの
pick
をedit
に書き換え保存 git commit --amend
git rebase --continue
$ git rebase -i HEAD~n
commit の取り消し
$ git reset --soft HEAD^
push の取り消し
$ git push -f origin HEAD^:master