◆githubからクローンする
https://github.com/rickumali/RickUmaliVanityWebsite.git
フォルダの選択は、実際に存在するとこまで行う。
その後、target dirで、新規のフォルダを記述する。
ripository > browse master's file
◆git bashを使用する
$ git --version
git version 2.10.1.windows.1
$ cd git
$ mkdir dokusyu_git_01
$ cd dokusyu_git_01/
$ git clone https://github.com/rickumali/RickUmaliVanityWebsite.git
Cloning into 'RickUmaliVanityWebsite'...
$ ls
RickUmaliVanityWebsite/ ディレクトリが出来てかた、cloneされた
$ cd RickUmaliVanityWebsite
◆1つのファイルの履歴を見る
$ git blame README.txt
◆リポジトリ全体の履歴
$ git log --oneline
◆configを見る
$ git config --list
◆configを設定する
$ git config --global user.name "xxx xxx"
$ git config --global user.email "xxx@yahoo.co.jp"
・文字化け対策
git config --global gui.encoding utf-8
◆個別のconfigを見る
$ git config user.email
$ git config user.name
◆ショートカット
Ctrl-K 右側の文字がすべて消える
Ctrl-U 左側の文字がすべて消える
Ctrl-A 行頭へ移動
Ctrl-E 行末へ移動
◆ファイルを作る
$ touch aaaaaaabbbbbbbb
◆日本語のhelp
https://git-scm.com/book/ja/v2
4)
◆新しいリポジトリを作る
$ mkdir buildtools
$ cd buildtools/
$ git init
◆作業ディレクトリの状況を見る
$ git status
◆ファイルを作って、管理する
$ echo -n contents
$ echo -n contents > filefixup.bat
$ git add filefixup.bat
$ git commit -m "This is the first commit message"
$ git blame filefixup.bat
$ git status
・一連のログを見る
$ git log
・コミットを構成しているファイルを見る
$ git log --stat
・リポジトリに入っているファイルのリストを見る
$ git ls-files
5)
$ git gui
rescan
選択して、stage to commit
commit
repository > Visualize master's History
gitkウィンドウが開く
git citool
6)
$ mkdir math
$ cd math
$ git init
$ echo "# Commit " > math.sh
$ git add math.sh
$ git commit -m "This is the first commit."
$ git log
$ echo "a=1" >> math.sh
$ cat math.sh
# Commit
a=1
$ git status
$ git diff
$ git commit -a -m "This is the second commit."
-aは,すべてのファイル
ファイルを変更した。
$ git add math.sh
ファイルをさらに変更した。
$ git status
$ git diff 作業エリアとステージングエリアと比較する
$ git diff --staged コミットしたものと、ステージングエリアのものとを比較
$ git gui
右クリック>stage hunk for commit
その後、メッセージを入れて、commit
$ git log --oneline
複数ファイルを作る
$ touch a b c d
$ git status
◆リハーサルを見る
$ git add --dry-run .
省略形: git add -n
$ git add .
$ git status
GUI でコミットする
$ git log
$ gitk
$ git add readme.txt
$ git commit -a -m "Adding readme.txt"
$ git log --shortstat --oneline
ヘルプを調べる
$ git help
$ git add -h
$ git add --help だと、英語のページが開く
$ cat --help
$ cat -n math.sh
git addしたのを取り消す
$git rm -cached math.h
$ git log --shortstat --oneline
7)
◆ステージングのコマンド
git add, git rm, git mv, git reset
・gitに入っているファイル群
$ git ls-files
・そのファイルがgit に入っているか?
$ git log readme.txt
・ファイルを削除してみると、
$ rm a
$ git status
・ファイルをステージングから削除
$ git rm b
$ git commit -m "Removed a and b"
・ファイル名を変更
$ git mv d another_rename
$ git status
$ git gui でコミット
$ git log --oneline
・ディレクトリを作り、ファイルを作り、コミット
手で、ディレクトリを作り、ファイルを作る
$ git gui
rescan
・コミットされているファイルの確認=ファイル・ブラウザ
repository>brouse master's file
commit > stage to commit
・部分的にステージングする
$ git gui
行を右クリックし、stage Line for Commit
$ git diff --staged
・手作業で部分をステージングする
$ git add -p
e
・ステージングへ加えた変更を削除 つまり、ステージングのリセット
$ git reset math.sh
・ファイルをコミット済のもので、上書きする=>チェックアウトする
$ git checkout -- math.sh
・コミット済のファイルを、削除し、削除を取り消す
$ git rm aaaaa.txt <<削除の事実をステージへ
$ git reset HEAD aaaaa.txt <<ステージから削除
$ git checkout -- aaaaa.txt <<リポジトリから、チェックアウト
8)
$ git log --parents
$ git log --parents --abbrev-commit
$ gitk
patch
tree
・検索
touching pathes: math.sh
コミットがboldになる
・コマンドラインで見る
$ git log --oneline → gitk の左上ペインと同様
・パッチ情報を見る
$ git log --patch
・パッチビューの表示と同様
$ git log --stat
・上2つの合体
$ git log --patch-with-stat
・math.shに関する情報のみ
$ git log --oneline math.sh
・コメントの書き方、1行をまとめ、1行空行、その後詳細
・sha1IDに変換する
$ git rev-parse HEAD
$ git rev-parse master
・特定のsha1IDをチェックアウトする
$ git checkout 2ff727f
…カレントのディレクトリの中身が変わった
$ git log --oneline 遡ったところまでしか表示されない
・元の場所に戻る
$ git checkout master
「タグ」
・タグをつける
$ git tag four_files_galore -m "This commit with four files" 2ff727f
・タグ一覧を見る
$ git tag
・指定のタグを見る
$ git show four_files_galore
・タグをチェックアウトする
$ git checkout four_files_galore
・戻る
$ git checkout master
演習)
・git を逆順に表示
$ git log --reverse
・直近N個を見る
$ git log -3
・相対時間で見る
$ git log --relative-date
(演習)
$ git add aaaaa.txt
$ git commit -m "change a little"
$ git log --oneline
・コミットメッセージを変更、複数行を入れる
$ git commit --amend -m "Fixed commit" -m "Second paragraph" -m "Wall of text"
(演習)
・3つ前のsha1IDを見る
$ git rev-parse master~3
・3つ前をgit show
$ git show master@{3}
$ git show master^^^
・コメントを検索
$ git rev-parse :/"Remove"
・タグの追加と削除
$ git tag aaaaa -m "test tag" 5829ae9
$ git tag -d aaaaa
(演習)
$ git log --reverse 逆順
$ git rev-parse :/"ubiquitous" コメント検索
$ git log --author="rgu@freeshell.org" コミットした人のemailで検索
$ git log | grep -B 1 rgu@freeshell コミットした人のemailで検索
$ git log --since=yesterday 昨日以降のコミットを表示
9)
$ git branch
・ブランチを作る
$ git branch new_feature
・切り替える
$ git checkout new_feature
new_featureでコミットを2回する
$ gitk
コマンドラインで、ブランチを見る
$ git log --graph --decorate --pretty=oneline --all --abbrev-commit
・エリアスに設定する
$ git config --global alias.lol "log --graph --decorate --pretty=oneline --all --abbrev-commit"
$ git lol
(ブランチの切り替え)
$ git branch
・ブランチをsha1ID、コメントを表示
$ git branch -v
$ git checkout master
masterでコミットする
$ gitk
・gitkで確認する
view > New View
□All (local) branches
Apply
□Remember This View
OK
$ git lol
$ gitk
branch 右クリック > Checkout this branch
$ git branch
(任意の場所でブランチを作成)
$ git checkout master
$ git log --oneline
任意の場所でブランチを作成
$ git branch fixing_readme c950c7c
$ git checkout fixing_readme
・ブランチ「fixing_readme」から、「another_fix_branch」を作成して、切り替える
$ git checkout -b another_fix_branch fixing_readme
・ブランチの削除
$ git checkout master
$ git branch -d fixing_readme
・ブランチの削除を取り消す
$ git branch -d another_fix_branch
Deleted branch another_fix_branch (was c950c7c).
$ git checkout -b another_fix_branch c950c7c
$ git lol
・sha1IDを失ったとき、ブランチ切り替えの、すべての記録
$ git reflog
・作業中に切り替える(stash)
$ git checkout master エラーが出る
$ git stash
Saved working directory and index state WIP on another_fix_branch: c950c7c ファイル名を変更、c、d
HEAD is now at c950c7c ファイル名を変更、c、d
$ git status
・stachをポップする
$ git checkout another_fix_branch
・何を退避させたか
$ git stash list
$ git stash pop
(演習)
・git guiでブランチを切り替える
branch > checkout
・gitk でブランチを作る
左上ペインで、該当行(コメントのとこ)を右クリック、create new branch
・gitkでブランチを削除
左上ペインで、該当ブラウザを右クリック、Remove this branch
・git GUIでブランチを削除
Branch > Delete > 上のリストで削除したいブランチを選択し、[Delete]をクリック
・ブランチ名の変更
git branch -m []
を指定しなければ、カレントブランチの名前が変更される
(演習)
・検索
$ git rev-parse :/"ファイル"
・ブランチを削除するとき、コミットしたものをマージしない場合、エラーになる
$ git branch -d new_feature
error: The branch 'new_feature' is not fully merged.
If you are sure you want to delete it, run 'git branch -D new_feature'.
・強制削除は
git branch -D new_feature
・削除したコミットを追う
git reflog
e6f5558 HEAD@{16}: commit: Adding a new file to a new branch
4cfd282 HEAD@{17}: checkout: moving from master to new_feature
・これらのラベルを指定してブランチを作り直せば、2つのコミットを、削除されたブランチから復活させることが可能
git checkout -b recovered_branch HEAD@{16}
(演習)
・変更したファイルを元に戻す
$ git checkout -- math.sh
・タグ「random_tag_on_file」を含むブランチを探す
$ git branch --contains random_tag_on_file
・何らかのブランチまたはタグで参照されているコミットだけを選択する
$ git log --oneline --decorate --simplify-by-decoration --all
$ git log --oneline --decorate --simplify-by-decoration --all --graph
10)
・ブランチの差分を調べる
$ git diff master...bugfix
$ git diff --name-status master...bugfix
M baz
・マージする
$ git merge bugfix
:wq
・親を見る
$ git log -1
・git guiでマージする
merge>local merge
merge ボタンクリック
・競合の対策
$ git merge bugfix
Auto-merging baz
CONFLICT (content): Merge conflict in baz
Automatic merge failed; fix conflicts and then commit the result.
$ git mergetool winmergeが設定済
$ git status
git add が暗黙のうちに行われた
(マージの途中で)
・マージを中止
$git merge --abort
・差分を見る
$ git diff
・fst-forward マージ
$ git checkout master
$ git merge new_feature
ブランチ「new_feature」は削除されない
コミットせずとも、マージできた。マージコミット自体も作らなかった。
11)
クローン
push / pull
remote
ベアリポジトリ…作業ディレクトリを持たないリポジトリ。作業の中継
・コマンドでクローン
$ cd math
$ git checkout master
$ cd ..
$ git clone math math.clone1
・git guiでクローン
clone Existing Repository >
Target Directoryは、まだないので、入力する。
$ gitk
表示をシンプルにするには、
View > Edit View >Simple history
コマンドでは、
$ git log --simplify-by-decoration --decorate --all --oneline
元のリポジトリ
$ git branch
another_fix_branch
* master
new_feature
cloneしたリポジトリ 元のリポジトリでアクティブだったブランチだけが現れる
$ git branch
* master
すべてを見るには、
$ git branch --all
* master
remotes/origin/HEAD -> origin/master
remotes/origin/another_fix_branch
remotes/origin/master
remotes/origin/new_feature
複製したリポジトリでの作業
$ git checkout another_fix_branch
$ git branch --all
* another_fix_branch
master
remotes/origin/HEAD -> origin/master
remotes/origin/another_fix_branch
remotes/origin/master
remotes/origin/new_feature
・ベアリポジトリを作る
$ git clone --bare math math.git
ベアリポジトリの中では、Git操作ができない
オリジナルへのリファレンスを持たない…スタンド・アローン
push, pull, cloneのみ
・ベアリポジトリから、クローンを作る
$ git clone math.git math.clone3
$ cd math.clone3
・gitヒストリーの、どの部分でも、ファイルのツリーを見る
$ git ls-tree HEAD
$ git ls-tree four_files_galore
・ブランチを作る
"$ git checkout -b clobe_another_fix_branch remotes/origin/another_fix_branch
"
Branch clobe_another_fix_branch set up to track remote branch another_fix_branch from origin.
Switched to a new branch 'clobe_another_fix_branch'
$ git checkout -b clobe_another_fix_branch2 another_fix_branch
Switched to a new branch 'clobe_another_fix_branch2'
12)
・ベアリポジトリから、クローンする
$ git clone math.git math.clone
$ cd math.clone
・リモートの名前を表示
$ git remote
origin
・リモートのURLを表示
$ git remote -v show
origin C:/Users/kxxxxxx/git/math.git (fetch)
origin C:/Users/kxxxxxx/git/math.git (push)
fetch:リモートからダウンロード:pullと同じ
push:リモートへアップロード
・carolのリポジトリにbobへのポインタを追加
$ git remote add bob ../math.bob
$ git remote
bob
origin
$ git remote -v show
bob ../math.bob (fetch)
bob ../math.bob (push)
origin C:/Users/kxxxxxx/git/math.git (fetch)
origin C:/Users/kxxxxxx/git/math.git (push)
…現実では、あまりないらしい
<リモートの調査>
・リモートのリファレンス(ブランチとタグのsha1ID)を返す
$ git ls-remote リモートリポジトリへ、接続を行い、リファレンスを取得する
$ git ls-remote origin
$ git ls-remote bob
From C:/Users/kxxxxxx/git/math.git
a8d9a49953254f6309891347726c02c06ef09aaf HEAD
dee0193bf10d6706b5c03338313f5a3905273357 refs/heads/another_fix_branch
a8d9a49953254f6309891347726c02c06ef09aaf refs/heads/master
f00747dd0d62dd943f7344c9518ce3e356c20ae4 refs/heads/new_feature
4c546f2b99b86c05500de4a8b62f973b6043c6e5 refs/tags/four_files_galore
2ff727fe9803285472cbddf6c19bf691b6ac112e refs/tags/four_files_galore^{}
refs/heads/ : ブランチ名
refs/tags/ :タグ名
carolは、クローンなので、math.gitとsha1IDは同じ。
$ git log -1
~/git/math.bobで実験
$ git checkout -b a_new_branch
~/git/math.carol で確認
$ git ls-remote bob
・githubからクローンする
$ git clone https://github.com/rickumali/math.git math.github
$ git remote -v show
origin https://github.com/rickumali/math.git (fetch)
origin https://github.com/rickumali/math.git (push)
・ネットワークをトレースする
$ GIT_TRACE_PACKET=1 git ls-remote
13)
~/git/math.carolで
$ git push origin master
Everything up-to-date
masterで変更
$ git status
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
プッシュする
$ git push origin master
紐づけられている場合
$ git push
$ git log -n 2
リモートに送られたことを確認する。orignのsha1IDを確認する。
$ git ls-remote origin
リモートとカレントの関連性の情報を見る
$ git remote -v show origin
~/git/math.bob で
$ git remote -v show origin
master pushes to master (local out of date)
・競合
・~/git/math.bob
ファイルを変更し、コミットする
・pushすると、競合する
$ git push origin master
(新規のブランチ作成、push)
$ git checkout -b new_branch master
・push時、新規のブランチは以下のようにする
$ git push --set-upstream origin new_branch
・構成ファイルを見る。正規表現付きで。
$ git config --get-regexp branch
・ブランチを削除し、pushする
$ git checkout master
$ git branch -d new_branch
$ git ls-remote origin リモートのチェック
$ git push origin :new_branch
形式)git push origin src:dest
(新規のタグ作成、push)
$ git tag
$ git tag -a two_back -m "Two behind the HEAD" HEAD^^
$ git log --decorate --oneline
$ git ls-remote リモートにないことを確認
$ git push origin two_back
・タグを削除のpush
$ git push origin :two_back
ローカルのタグは削除していない。削除するには、
$ git tag -d two_back
14) pull
・carolから、math.gitが変更があるか調べる
$ git remote -v show origin
master pushes to master (local out of date)
$ git push でエラーが起きる
・pullする
$ git pull
・math.billを変更、コミット、push
$ echo "Tiny change" >> another_rename
$ git commit -a -m "Another tiny change"
$ git push
(pullの理解のための実験)
・math.carolで、fetchする
$ git log --decorate --oneline --all
$ git fetch
masterの最新のコミットのshaIDを取得
$ git rev-parse FETCH_HEAD
$ git rev-parse origin/master
$ git diff HEAD..FETCH_HEAD HEAD..FETCH_HEADの差分
・マージする
$ git merge FETCH_HEAD
(理解のための実験)
bill と carolで同じ箇所を同じ文で変更
billは、push。carolは、pull、pull時、vi のメッセージ入力をしないで、保存。エラーが出る。
$ git commit
デフォルトエディタになるので、そのまま保存
carolで
$ git push
billで
$ git pull
carolとbillが同期
(競合のための実験)
billとcarolで同じ場所を変更し、billでpushし、carolでpullする
$ git pull
CONFLICT (content): Merge conflict in another_rename
Automatic merge failed; fix conflicts and then commit the result.
確認する
$ git status
Your branch and 'origin/master' have diverged, 分岐している
and have 1 and 1 different commits each, respectively.
ここで、競合するファイルを開く
<<<<<<< HEAD
ABC DEF GHI
=======
JKL MNO PQR
>>>>>>> aad3d9f29afc5a064418c650ca61fb279c68d0c9
修正後
ステージへ上げる
$ git add another_rename
$ git citool でコミットする
その後、push
$ git push
再び、billに入り、pull
$ git log --decorate --graph --all --oneline
(fast forwardのみ受け付ける)
$ git pull --ff-only
fatal: Not possible to fast-forward, aborting.
pullできなかった
先にpullする
$ git remote -v show origin
$ git pull
$ git status
$ git push
(pull のトラブルを防ぐ、fetch とマージ)
1.billで変更、commit, push する
2.carolで変更、commitする。
$ git commit -a -m "一旦、修正した"
$ git fetch
$ git diff HEAD FETCH_HEAD
ここで何が変更されるかチェックした
$ git merge FETCH_HEAD
Automatic merge failed; fix conflicts and then commit the result.
ここでanother_renameを修正
$ vi another_rename
>>>>などを修正
$ git commit -a -m "一旦、修正した 2"
$ git merge FETCH_HEAD
Already up-to-date.
$ git pull
Already up-to-date.
$ git push
1.billで他のファイルを変更、commit
$ git pull で、viが開き、mergeの自動メッセージ、保存し、閉じる
$ git push
2.carol で他のファイルを変更、commit
$ git fetch
$ git diff HEAD FETCH_HEAD
$ git merge FETCH_HEAD
競合がないとき
自動メッセージ、保存し、閉じる
$ git pull
Already up-to-date.
$ git push
3.bill でpull
$ git pull
Fast-forward
競合させて、解消する
mergeのツールではどうなるのか?
できるだけ、ツールを使う
1.billでファイルを変更
$ git gui commitする
$ git pull
$ git push
2.carolで変更
$ git gui commitする
$ git fetch
$ git merge FETCH_HEAD
$ git mergetool でマージ
$ git gui でcommitする
$ git merge
Already up-to-date.
$ git push
途中でpullして、commit時に競合することはないのか?
1.billでファイルを変更
$ git gui commitする
$ git pull
$ git push
2.carolで変更
$ gitk でブランチがどうなっているか調べる
ローカルの変更について、表示されていた
$ git pull
error: Your local changes to the following files would be overwritten by merge:
another_rename
Please commit your changes or stash them before you merge.
Aborting
先にコミットする か、 stashするようにとなった
$ git gui でcommitする
$ git mergetool
No files need merging まだ、マージしてないので、動作しない
$ git merge
$ git mergetool でマージする
$ gitk
$ git gui でcommitする
$ git fetch
$ git diff HEAD FETCH_HEAD
$ git pull
$ git push
3.billで
$ git fetch
$ git diff HEAD FETCH_HEAD
$ git merge
できるだけ、gitkのすべてのモードでチェックすること
(エラー)
billのブランチanother_fix_branchで、
$ git pull
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details.
git pull
If you wish to set tracking information for this branch you can do so with:
git branch --set-upstream-to=origin/ another_fix_branch
$ git branch --all
* another_fix_branch
master
remotes/origin/HEAD -> origin/master
remotes/origin/another_fix_branch
remotes/origin/master
remotes/origin/new_feature
$ git branch --set-upstream-to=origin/another_fix_branch another_fix_branch
Branch another_fix_branch set up to track remote branch another_fix_branch from origin.
読んでおく。
http://qiita.com/kobake@github/items/fb317b4fdacad718a4b2
15) git log
・マージしているコミットを探し出す
$ git log --parents --oneline
$ git --no-pager log 66f9741 -n 1
$ git log --merges
・1つのファイルの履歴
$ git log --oneline readme.txt
・2つのファイルの履歴
$ git log --oneline readme.txt math.sh
もう少し詳しく
$ git log --oneline --stat readme.txt math.sh
・特定のコミットメッセージ「change」を探し出す
$ git log --grep=change
該当期間のコミットを探す
$ git log --since 09/08/2017 --until 09/09/2017
著者による抽出
$ git shortlog
$ git shortlog -e emailも表示
$ git log --author="xxx xxx"
$ git log --author="xxx"
$ git log --author="@yahoo.co.jp"
(ファイル間の相違)
$ git log --stat HEAD^..HEAD
$ git log --patch HEAD^..HEAD
最初に、--statで調べた後、sh1IDで調べる
$ git log --patch 6b6d0d6^..6b6d0d6
$ git log --patch 6b6d0d6^..6b6d0d6 -- a b
(ブランチを絞り込み、)
$ git branch --column
$ git log --graph --decorate --oneline --all
$ git log --graph --decorate --oneline branch_03
$ git log --graph --decorate --oneline branch_03 branch_10 master
(sha1IDがどのブランチに属しているか?)
$ git log --graph --decorate --oneline
$ git log 917c585 -n 1
$ git name-rev 917c585 近いブランチから、コミットの名前を生成する
917c585 master~2
$ git branch -r --contains cc9bccd
(gitkによる探索)
$ gitk --all
edit view > All refs 外す、Branches & tagls に入力
$ gitk branch_03 branch_10 master
(簡易ビュー)
チェック:All refs , Simple history
(ファイルを探す)
「change」という言葉を含むファイルを検索
$ git grep change
another_rename:Small change
another_rename:Tiny change
another_rename:Small change2
(特定のファイルの履歴を調べる)
$ gitk another_rename
$ git show c7afa1b
$ git show 8911263f
(コードの特定行を更新したリビジョンを調べる)
$ gitk another_rename
Diff画面で右クリック>Run Git Gui Blame on This Line
すべての行が、どこで入ったのか、調査できる
$ git gui blame another_rename
$ git gui blame d311 another_rename 特定のリビジョンで
ファイルブラウザ起動、ファイルの一覧を見る
$ git gui browser master
$ git gui browser HEAD
どの行がどこで入ったか?
$ git blame another_rename
それをファイルに保存
$ git --no-pager blame another_rename > blame_another_rename.txt
(notesをつける)
$ git log -1
$ git notes add -m "ここでバグが生まれた"
$ git log -1
17) ワークフロー
(git フロー)
$ mkdir nvie
$ cd nvie
$ git init
$ git commit --allow-empty -m "Initial commit"
$ git branch develop
$ git log --decorate
$ git checkout -b feature/sum develop
$ git branch
・developブランチにマージ
fast forward マージを防ぎ、マージのヒストリが保存される
$ git merge --no-ff feature/sum
$ git log -1
ブランチ「 feature/sum」を削除
$ git branch -d feature/sum
・releaseブランチを作成、バージョンを上げて、コミット
$ git checkout -b release-1.0 develop
sum.shのバージョンの記載を上げる
# Version 1.0
$ git commit -a -m "Bumping to version 1.0"
・リリースする(releaseブランチをmasterにマージする)
$ git checkout master
$ git merge --no-ff release-1.0
・タグを追加
$ git tag -a V1.0 -m "Release 1.0"
・developに戻す
$ git checkout develop
$ git merge --no-ff release-1.0
・リリースブランチは不要になったので削除
$ git branch -d release-1.0
(git hub フロー)
$ mkdir gh-flow
$ cd gh-flow/
$ git init
$ git commit --allow-empty -m "Initial commit"
$ git checkout -b sum_program master
$ git branch
$ git add sum.sh
$ git commit -m "The sum program"
masterにマージする
$ git checkout master
$ git merge sum_program
18) ワークフロー
githubで
$ cd ../math
$ git remote -v show
$ git remote add github https://github.com/Ckxxxxxx/math2.git
$ git remote -v show
$ git push -u github master
u オプション
・push時、新規のブランチは以下のようにする
$ git push --set-upstream origin new_branch
(githubでフォークし、クローンする)
rickumariでフォーク
$ rm -rf math 既存のmathを消す
$ git clone https://github.com/Ckxxxxxx/math.git
(ローカルで変更し、フォークしたgitにpushし、元のrickumariにgithubでプルリクを出す)
$ cd math
$ git branch
readme.txt変更
$ git commit -a -m "Small change to fork"
$ git remote -v show
$ git push
To https://github.com/Ckxxxxxx/math.git
・プルリク
githubのmath、
This branch is 1 commit ahead of rickumali:master.
>create pull request >メッセージなどを入力し、 create pull request
クローズ
close pull request
18) サードパーティー製ソフト
sourceTree
eclipse
ファイル>新規>プロジェクト>
一般>プロジェクト>
プロジェクト名
ロケーション
・ファイルを変更しコミット
ファイル>右クリック>チーム>索引に追加
ファイル>右クリック>チーム>コミット
プロジェクト選択>チーム>ヒストリーに表示
コミットメッセージを選択>右クリック>コミットビュアーで開く
下のタブ>コミット または 相違
16) git rebase
(開始地点の変更)
$ git checkout new_feature
$ git log --oneline master..new_feature
・new_featureを、masterブランチからの最新のコミットによって、リベースする
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: Adding a new file to a new branch
Applying: Starting a second new file
$ git log --oneline master..new_feature
sha1IDが変化している
(リポジトリを元に戻す)
・以前のsha1IDを探す
$ git reflog
2a7c685 HEAD@{0}: rebase finished: returning to refs/heads/new_feature
2a7c685 HEAD@{1}: rebase: Starting a second new file
3d7c20d HEAD@{2}: rebase: Adding a new file to a new branch
acd4f3c HEAD@{3}: rebase: checkout master
0135f1c HEAD@{4}: checkout: moving from master to new_feature
$ git reset --hard HEAD@{4}
HEAD is now at 0135f1c Starting a second new file
(ローカルコミットの整理)
$ git branch new_featureにいること
$ git log -n 2 --stat --oneline
・インタラクティブにコミットを編集する
$ git rebase --interactive master
pick 5e1465b Adding a new file to a new branch
融合する squash 0135f1c Starting a second new file
:wq
$ git log -n 1 --stat
20) git config
$ git config --local --list
$ git config --global --list
$ git config --system --list
c は使い慣れない構成をテストするのにいい
$ git -c log.data=relative log -n 2
日付を相対表示に設定する
$ git config --local log.date relative
$ git log -n 2
元に戻す
$ git config --local --unset log.date
(無視ファイル)
優先順位
1.コマンドラインで指定したパターン
2.作業ディレクトリにある.gitignore ファイルから読んだ
3.gitフォルダ/info/excludeから読んだパターン
4.構成変数core.excludesFileで指定されたファイルから読んだパターン
$ cd math
$ touch file.obj
$ git status
$ echo "*.obj" > .gitignore
$ git status
.gitignoreはコミットして、共通で使用する