gitいろいろ#memo #git

text
阅读 46 收藏 0 点赞 0 评论 0

git
git いろいろ

git config --global merge.conflictstyle diff3



git config --global rerere.enabled true


git config --global color.ui auto   # 出力先が端末のときに色をつけて表示する


git diff --color-words  # 差分を単語単位で色分けで表示する


設定のために、リポジトリのルートに.gitattributesを作成する
.gitattributes
*.c diff=cpp
*.h diff=cpp
*.cpp diff=cpp
*.hpp diff=cpp
*.m diff=objc
*.java diff=java
*.html diff=html
*.pl diff=perl
*.pm diff=perl
*.t diff=perl
*.php diff=php
*.py diff=python
*.rb diff=ruby
*.js diff=java

.gitattributesや.gitignoreを全てのリポジトリに適用する

同じフォーマットのファイルをホームディレクトリなどに置いておき、~/.gitconfigに設定しておきます。
git config --global core.attributesfile ~/.gitattributes_global
git config --global core.excludesfile ~/.gitignore_global


git status --short --branch

左がmergeされるbranchまたはadd済みで、右がmergeするbranchまたはローカル変更であることを覚えておくと便利


git log --stat --decorate --find-renames

git log --graph --decorate --onelineでGUIツールっぽくcommit/merge履歴を表示

git log -p      # 差分を表示
git log --stat  # ファイルごとの変更行数を表示

git config --global diff.renames tr
ename+内容の差分で表示してくれる


git log --stat --find-renames
git diff --find-renames
git log -p --find-renames

git log --follow [filename] 
ファイル名変更を自動で追跡


git log A..Bで特定範囲のcommit履歴を表示する

git log 1.0.0..             # version 1.0.0から現在のbranchへのcommit履歴を表示
git log master..feature     # feature branchに積まれたcommit履歴を表示(masterが進んでいてもOK)


git diff A...Bでbranch全体の差分を表示する

branchに積まれた差分全体のdiffを表示するために、git logでcommit番号を確認する必要がなくなります。
git diff master...feature   # feature branchに積まれた差分を表示(masterが進んでいてもOK)
どのファイルが変更されたのかを見たい場合は、--name-onlyをつけます。

git diff A..BはAとB間で普通のdiffを表示します。
git diff Aはgit diff A..HEADと等価です。
枝分かれしたcommit番号自体を知りたいときは、git merge-base A Bを使います。 git diff A...Bはgit diff `git merge-base A B`..Bと等価です。


git diff --name-onlyで変更されたファイル一覧を取得する


prove `git diff --name-only | egrep '\.js$|\.pm$'`   # perlのテストを実行
jshint `git diff --name-only | egrep '\.js$'`        # jshintを実行
もちろん、git addしたファイルを表示する--cachedや、git diff [branch名]のような指定も可能です。
your-test-tool `git diff --name-only --cached`           # commit予定の差分をテスト
your-test-tool `git diff --name-only origin/master...`   # origin/masterにmerge予定の差分をテスト


gitconfigにaliasを作成する

例えば、commit/merge履歴をグラフで表示するコマンドをgit graphにしたい場合、下記のコマンドでOKです。
git config --global alias.graph 'log --graph --decorate --oneline'
削除は下記のとおりです。
git config --global --unset alias.graph



评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号