Last active
July 4, 2021 08:43
-
-
Save naokazuterada/3445332 to your computer and use it in GitHub Desktop.
Git 覚書
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 前回のcommitメッセージをviで編集。 | |
# commitメッセージの間違いに気づいた時に便利。但し、既にpushまでしちゃった場合は、やめたほうがいい。<a href="http://progit.org/book/ja/ch6-4.html">参考元</a> | |
git commit --amend | |
# Githubの自分のリポジトリからクローンするときに、 | |
git clone https://github.com/hoge/moge.git | |
# のように、httpsでクローンしてしまうと、変更を加えてリモートにプッシュしようとしたときに、毎回usernameやpasswardを求められる | |
# クローンした後からでも、リモートのURLを編集できるので、下のようにして、SSHのURLに変更すればこの問題を解決できる | |
git remote set-url origin git@github.com:hoge/moge.git | |
# 追加ファイルを検知してステージング | |
git add . | |
# git rmを用いなかったファイル削除も検知&ステージング | |
# 新規追加ファイルは検知されない。 | |
git add -u | |
# 上の2つの合わせ技的なやつ | |
# ファイルの追加削除、リネーム等を検知&ステージング | |
git add -A | |
# herokuからアプリをclone | |
git clone git@heroku.com:APP_NAME.git -o heroku | |
# gitignoreにファイルを追加したら一旦キャッシュを消すと反映される(コミットしていないデータは消失する) | |
git rm -r --cached . | |
# wp/wp-content/uploads/以下のファイルをhistoryから削除 | |
git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch filename' HEAD | |
# wp/wp-content/uploads/以下のファイルをhistoryとワークツリーから削除 | |
# git filter-branch -f --index-filter 'git rm -rf --ignore-unmatch wp/wp-content/uploads' HEAD | |
# ↓ git filter-repo というのにアップデートされたらしい [Ref](https://qiita.com/Freesia_t/items/2ce56f4df676e8377db9) | |
# .DS_Storeという名前のファイルをべて削除 | |
git filter-repo --invert-paths --path '.DS_Store' --use-base-name --force | |
# Ref: https://sleepost.hatenablog.com/entry/2021/05/22/023255 | |
# 特定のファイルを全ての履歴から削除 | |
git filter-repo --path xxx --invert-paths | |
# 例)dir以下を全て削除 | |
git filter-repo --path dir/ --invert-paths | |
# 例)readme.mdを削除 | |
git filter-repo --path readme.md --invert-paths | |
# ちなみに --invert-paths を書かないと『そのファイルだけ残して後は全て消す』になる | |
# gitignoreする前に登録してしまった.DS_Storeを全消去 | |
find . -name .DS_Store -print0 | xargs -0 ls #まず確認 | |
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch | |
git commit -m "delete all .DS_Store" | |
# wp/wp-content/uploads/以下のファイルの場合 | |
find ./source/wp/wp-content/uploads -name * -print0 | xargs -0 ls #まず確認 | |
find ./source/wp/wp-content/uploads -name * -print0 | xargs -0 git rm -r --ignore-unmatch | |
git commit -m "delete all files in wp-content/uploads" | |
# submodule ---------- | |
# プロジェクト内に別のリポジトリを追加 | |
git submodule add [repository] [dir] | |
# 追加したリポジトリを初期化&更新 | |
git submodule update –init | |
# もしくは | |
git submodule init | |
git submodule update | |
# updateは親の方に登録された子のコミットポイントに子を合わせるだけ | |
# 子の中身を子の共有リポジトリからプルしたい場合は下記 | |
git submodule foreach 'git checkout master; git pull' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment