「.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
git --version
インストールされない場合はインストール
sudo apt update sudo apt install git
Gitにあるリポジトリを操作
(testリポジトリのtestブランチ)
git clone https://github.com/daisukenishino2/test.git cd test
git switch test
git switch -c your-task
nano README.md
ステージングに追加
git add README.md
git add .
git commit -m "updated."
git push origin main
branchする
git branch <new-branch>
branchをcheckoutする(切り替える)。
git checkout <existing-branch>
git checkout -b <new-branch>
git checkout -b <new-branch> <existing-branch>
branchをmergeする。
git merge <branch>
git merge --no-ff <branch>
branchを削除する。
git branch -d <experimental>
git branch -D <experimental>
git clone は既存の git repositoryのclone (コピー) を作成する
git clone <repo>
git clone <repo> <directory>
remote repositoryからfetchする。
git fetch <remote>
git fetch <remote> <branch>
remote repositoryからpull(fetch & merge)する。
git pull <remote>
git pull --rebase <remote>
remote repositoryへpushする。
git push <remote> <branch>
git push <remote> --all
git push <remote> --tags
ステージング・エリアにaddする。
git add <file>
git add <directory>
git add -p
ステージング・エリアからcleanする。
git clean -n
git clean -f
git clean -f <path>
git clean -df
git clean -xf
commitのreset
git reset <file>
git reset
git reset --hard
<commit> = commit の"SHA-1 id"
変更のcommit
git commit
git commit -m "<message>"
commitのrevert
git revert <commit>
commitのreset
git reset <commit>
git reset --hard <commit>
branchの確認
git branch
git branch -r
git branch -a
git branch -m <branch>
logの確認
git log
git log -n <limit>
git log --oneline
git log --stat
git log -p
statusの確認
git status
Rebase、Reset、Revert の違いと使い分け
「履歴を綺麗にしたい」場合に使う(ローカルでのみ行うべき)
https://www.google.com/search?q=Rebase&udm=2
「間違えてコミットした」場合に使う(ローカルでのみ行うべき)
モード | `git reset <commit>` の影響 |
`--soft` | コミット履歴だけ戻し、インデックスやワーキングツリーの変更はそのまま残る |
`--mixed`(デフォルト) | コミットとインデックスは戻るが、ワーキングツリーの変更は残る |
`--hard` | コミット、インデックス、ワーキングツリーすべてを戻す(変更が完全に消える) |
「リモートに影響を与えずに変更を取り消したい」(安全なので推奨される)場合に使う
コマンド | 目的 | 履歴の改変 | 影響範囲 |
rebase | 履歴を整理・ブランチを最新にする | する | ローカルのみ(要 `push --force`) |
reset | コミットを取り消す・巻き戻す | する | ローカルのみ(特に `--hard` に注意) |
revert | 特定のコミットを打ち消す | しない | リモートでも安全 |