1. gitで双方向にmergeしない
自分のブランチにmasterをmergeしない
local branchでの作業を終えたら、branchを消去してmasterブランチのみ残す
command
masterブランチからexperimentalを作る
git branch experimental
git checkout experimental
git push experimental
git checkout master
git merge --no-ff experimental
git branch -d experimental #ローカルブランチを削除
git push --delete origin experimental #リモートブランチを削除
- Reference
- gitで双方向にmergeしてるとひどいはまり方をするときがある件
git remote branch delete: unqualified destination
git fetch -p origin
-
意味
- to make refs/remotes/origin/my_remote_branch go away if it's already deleted in origin
- The -p option tells fetch to delete any tracking branches that no longer exist in the corresponding remotes
- The fact that refs/remotes/origin/my_remote_branch exists in your local repository does not imply refs/heads/my_remote_branch exists in the origin remote repository
-
Reference
2. サイドlocal branchが必要な場合はリモートのgitブランチをローカルにチェックアウトする
リモートのgitブランチをローカルにチェックアウトする
git checkout -b other_branch origin/other_branch
3. リモートレポジトリ同時をmerge
- git checkout master
- git merge remotes/origin/develop01
4. リモートブランチとローカルブランチの差分を表示する
command
- 現在のローカルブランチとリモートブランチの差分を表示
- git diff remotes/origin/master
- 現在のローカルブランチとリモートブランチの差分を簡易表示
- git diff --name-status remotes/origin/master
reference
5. Git Log
- Find Commit ID
- git log --date=short --no-merges --pretty=format:"%cd %s %h (@%cn) "
- Reference
- Often Command
- gitlog -p
- git log --oneline
- Reference
6. Git diff
- Find Diff
- git diff HEAD^ or git diff commitID^
- Reference
7. gitのコミットログの内容を修正
- 編集対象のコミットを選ぶ
- git rebase -i HEAD~3
- コメントを編集する
- git commit --amend
- 編集したコメント保存
- git rebase --continue
- Reference
- gitのコミットログの内容を修正
8. Conflict
- Get 競合ファイル一覧
- git diff --name-only --diff-filter=U
- Reference
9. Gitで状態別に一括追加
- コマンド一発!Gitで状態別に一括追加する方法
- git ls-files --others --exclude-standard | xargs git add
- others
- regex='.*json'
- for file in
git ls-files --others --exclude-from=.gitignore
; do - if [[ $file =~ $regex ]]; then continue; fi
- git commit add $file
- done
- Reference
10. まとめて.gitignoreする方法
- 無視したいファイルをリポジトリから削除(管理対象から外れるだけで、ローカルにあるファイルは削除されない)
- git rm --cached hoge.tmp
- 大量のファイルが登録されている場合
- git rm --cached
git ls-files --full-name -i --exclude-from=.gitignore
- git rm --cached
11. Gitにおけるローカルブランチ/リモートブランチの整理
ブランチの種類
- ローカルブランチ
- ローカルで開発するときにcheckoutで開いてコミットしていくお馴染みのもの
- リモート追跡ブランチ
- ローカルに保持している、クローン元リポジトリのブランチを取り込んだもの
- リモートブランチ
- リモート追跡ブランチを通じてしか知り得ない
挙動整理
- ローカルでコミット無し、リモートでコミットされていた場合
- fetchでリモートの情報を取得する
- (git checkout develop)
- git fetch
- ローカルブランチにリモートのコミットCが継ぎ足される
- リモート追跡ブランチorigin/developが更新さる
- ただし、ローカルブランチdevelopは変更されない
- なので、fetchしたら速やかにマージする
- git checkout develop
- git merge origin/develop
- fetchでリモートの情報を取得する
- ローカルでコミット有り、リモートでコミット無しの場合
- リモートに更新情報が無いのでfetchやpullを行っても何も変化なし
- ローカルコミットをリモートに反映させる必要が有る
- ローカルとリモート両方でコミット有りの場合
- https://qiita.com/forest1/items/db5ac003d310449743ca
12. Git 過去の特定のコミット位置からブランチを切りたい
commit history
git log --all --decorate --graph --oneline
command
git checkout -b <new_branch> <commit_hash>