準備
- repoをforkする
- cd tkobayas
- git clone git@github.com:tkobayas/drools.git
- cd drools
- git remote add upstream https://github.com/kiegroup/drools.git
- git fetch upstream
masterを同期
- git fetch upstream
- git checkout master
- git reset --hard upstream/master
- git push origin
long running branchの場合、masterを同期してからマージ
- git checkout myTopic
- git merge master
ブランチで作業
- git branch myTopic master
- git checkout myTopic
...
- git add xxx/xxxx.java
- git commit -m "aaaaaaaaaaaaa"
- git add yyy/yyyy.java
- git commit -m "bbbbbbbbbbbbb"
- git rebase -i HEAD~2
- squash/fixup
- 混ぜ込みたいコミットを f にするだけ(ひとつ前のコミットに結合される)
- 各コミット順番変えてもよし(可能であれば)
- 一個前のコミットと合成するだけなら commit --amend でもよし
- squash/fixup
- JIRAを作成して、そのJIRAの作業するときはブランチ名をJIRA IDに変更。コミットログにもJIRA ID を入れ直す
- git branch -m myTopic guvnor9999
- git commit --amend -m "DROOLS-9999: xxxxxxxx"
- git push origin drools9999
ブランチ作業中に upstream が進んだら
- git fetch upstream
- git rebase upstream/master
WIPを退避/もどす
- git stash
- pull とか rebase とかやる
- git stash list
- git stash apply stash@{0}
log
- git log --oneline
- 一行ログ。短縮コミットID
- git shortlog
- コミット数を調べる
- git log --name-status
- 変更されたファイル名を見たい(diffより簡潔に)
どのコミットで削除されたかしらべるとき
- git log -p -S 'hostport' ./uberfire-nio2-backport/uberfire-nio2-impls/uberfire-nio2-jgit/src/main/java/org/uberfire/java/nio/fs/jgit/JGitFileSystemProvider.java
ファイルが削除された場合
diff
- git diff
- ワーキングツリーとインデックス
- git diff --cached
- インデックスとHEAD
- git diff HEAD
- ワーキングツリーとHEAD
- git diff commit-id..commit-id ファイル名
- 特定コミット間の差分
- git show commit-id
- そのコミットを見たいとき
リモートのブランチをチェックアウト
- git checkout -b hogehoge origin/hogehoge
ブランチ削除
- git branch -d hogehoge
リモートトラッキングブランチ削除
- git branch -dr upstream/hogehoge
ブランチリネーム
- git branch -m fugafuga
- リモート上のブランチ削除
- git push --delete origin BRANCHNAME
タグ見る
- git tag -l
- git for-each-ref --format='%(tag) %(taggerdate:short)' refs/tags
タグをチェックアウト
- git checkout -b 1.6 refs/tags/v1.6
- ブランチを作る
- git checkout refs/tags/v1.6
- ブランチを作らない。
- cptag
- ソースをコピー
- cptag
- ブランチを作らない。
- github上にタグがあるのにこっちで見えないよ
- git fetch --tags
タグつける
- git tag -a 1.0.0 -m 'version 1.0.0'
- git push origin 1.0.0
git add の取り消し
- トラック済みのファイル
- git reset HEAD foo.txt
- 新規ファイル
- git rm --cached foo.txt
- ディレクトリの場合 git rm -r --cached myDir
トラックされているファイルの更新のみまとめてadd(新規ファイルは除く)
- git add -u
新規作成/更新/削除まとめてadd
- git add -A
トラックされているファイルの更新のみまとめてcommit
- git commit -a
"cherry picked from commit" 付きで cherry-pick
- git cherry-pick -x
コミット取り消し(無かったことにする)
- git reset --hard HEAD^
クリーンアップ
- git reset --hard
- git clean -df
ワーキングツリーのファイルの状態をインデックスの状態(なければHEAD)に戻す
- git checkout foo.txt
rebase などの後で push して
[tkobayas@tkobayas rewards-basic]$ git push To git@github.com:tkobayas/jbpm5example.git ! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:tkobayas/jbpm5example.git' To prevent you from losing history, non-fast-forward updates were rejected
と怒られた場合
- git push -f
特定の commit id で直接表示
- https://github.com/
/ /commit/ - 例) https://github.com/droolsjbpm/jbpm-designer/commit/65017f4ec16b6774395f2cc6f1488e762571a974
remote 確認
- git remote -v
remote の URL を変更 (e.g. HTTPS -> SSH)
bisect
git bisect start <new-bad-commit> <old-good-commit>
中間のコミットが選ばれる。
テスト。
だめなら(= 悪いコミットが混入済み)
git bisect bad
よければ(= 悪いコミットが混入前)
git bisect good
で、次のコミット候補が選ばれる。で、最終的に絞られる。
git bisect view
で、現時点の候補コミットを見る
git bisect run <script-file>
なら全部自動でやってくれる(スクリプトは exit 0 で good, exit 1 で bad)
github で検索
is:open is:pr review-requested:tkobayas is:open is:pr involves:tkobayas
レビュー待ちリスト
https://github.com/pulls/review-requested
メンションされたリスト
https://github.com/pulls/mentioned
log
http://samuraism.jp/diary/2011/08/05/0000000000000.html
ワークフロー
http://sandofsky.com/blog/git-workflow.html
githubでコミットをリスト
pull request のリスト
- https://github.com/pulls
- https://github.com/droolsjbpm/drools/pulls/
- https://github.com/pulls?utf8=%E2%9C%93&q=author%3Atkobayas+created%3A%222015-03-01+..+2016-02-29%22
- author, 期間指定
- http://git-scm.com/book/en/Git-Tools-Debugging-with-Git
- git blame -C
- git bisect
pull request を diff でダウンロード
- http://stackoverflow.com/questions/6188591/download-github-pull-request-as-unified-diff
- .diff をつけるだけ
pull request をローカルにチェックアウト
- https://help.github.com/articles/checking-out-pull-requests-locally/
- "command line instructions" をクリック
PR をローカルに cherry-pick
git remote add mario https://github.com/mariofusco/drools.git git fetch mario git log --oneline mario/d4623 git cherry-pick c3f38b6
PRブランチに直接コミット&push(github_botとか)
git checkout -b 7.67.x_DROOLS-7604-karaf-itests-mvel-fix upstream/7.67.x_DROOLS-7604-karaf-itests-mvel-fix <修正> <コミット> <github Token クリップボードにコピーしておく> git push upstream 7.67.x_DROOLS-7604-karaf-itests-mvel-fix
opensshのダイアログで
ユーザ名
personal access token
を入れる
personal access token は github -> Settings -> Developer Settings -> Personal access tokens (classic)
scope は repo
gh
[tkobayas drools]$ gh pr checkout 2963 remote: Enumerating objects: 80, done. remote: Counting objects: 100% (80/80), done. remote: Compressing objects: 100% (24/24), done. remote: Total 80 (delta 35), reused 80 (delta 35), pack-reused 0 Unpacking objects: 100% (80/80), done. From git://github.com/kiegroup/drools * [new ref] refs/pull/2963/head -> DROOLS-5288 Switched to branch 'DROOLS-5288'
SSH
複数SSH
http://tanjoin.hatenablog.com/entry/2013/11/12/131437
GIT_SSH_COMMAND="ssh -vvv" git clone git@github.com:tkobayas/servlet-exam.git
Jenkins CI in github
The main advantage of being in the org. unit is that our automated CI jobs will now recognize you as trusted submitter and CI builds for your PRs will be executed automatically. So far you might have noticed that in you PRs, there was another comment like "Can one of the admins verify the patch?". That means someone from the droolsjbpm org.unit needed to approve the PR before the build started, which is not necessary in you case (it is basically just security precaution as we don't want to build every single PR submitted to our repos). The PR will not be merged automatically. That still needs to be done by humans. The PR changes will be merged to testing branch and Jenkins CI build will be executed. Results from the build are then shown directly in the PR. This is there to make sure new changes do not introduce test/compilation failures. There really isn't any document that would explain the process in detail. We use standard GitHub support + this Jenkins plugin: https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin