C feature 1. git pull 2. git switch -c D E F HEAD 3. git add → 4. git commit 5. git push origin/feature E F 6. merge (Pull Request) G ワーキングディレクトリ (変更したファイル) Git/GitHub 知っておくと便利かも Tips 7
A B C D E main feature After Rebase A B C D' E' feature main D' とE' はD とE と同じ変更内容だが、新しいコミットハッシュを持つ $ git rebase <branch > Git/GitHub 知っておくと便利かも Tips 13
message > という形式。この文字列を操作してコミットを操作する。 pick 2e07860 機能A を実装 fixup eec4f44 typo 修正 pick 4c088b1 機能A のテストを追加 pick f813dac README を更新 # Rebase 7890123..3456789 onto 7890123 (4 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # b, break = stop here (continue rebase later with 'git rebase --continue') # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # u, update-ref <ref> = track a placeholder for the <ref> to be updated # # These lines can be re-ordered; they are executed from top to bottom. # # If you remove a line here THAT COMMIT WILL BE LOST. # # However, if you remove everything, the rebase will be aborted. Git/GitHub 知っておくと便利かも Tips 19
ることが原因で pull, rebase ができない $ git status -s M hoge.txt $ git pull error: cannot pull with rebase: You have unstaged changes. error: Please commit or stash them. $ git rebase main error: cannot rebase: You have unstaged changes. error: Please commit or stash them. Git/GitHub 知っておくと便利かも Tips 25
feature-1 ブランチに main ブランチの変更を取り込むために git rebase main を実行 4. コンフリクトが発生したが、とても複雑だったため、コンフリクト解消は一度取りやめた( git rebase --abort ) 5. main ブランチからブランチを切り直すことにしたので、 git reset main を実行して、コミットのみを main ブランチ と同じ状態にしようとした 6. しかし、手が滑って git reset main --hard を行い、feature-1 ブランチで行っていた変更全てが失われてしまっ た… Git/GitHub 知っておくと便利かも Tips 31
Targeted Attack on Coinbase Expanded to the Widespread tj- actions/changed-files Incident: Threat Assessment (Updated 4/2) https://unit42.paloaltonetworks.com/github-actions-supply-chain-attack/ 攻撃者は悪意のあるコミットを行う際に Renovate になりすましてコミットを追加したことが報告されている。 The attacker was able to add the malicious commit (0e58ed8) to the repository by using a GitHub token with write permissions that they obtained previously. The attacker disguised the commit to look as if it was created by renovate[bot] — a legitimate user. コミッターのなりすましは攻撃の発見が遅れる原因となるとともに、原因調査を難しくする。 こういったなりすましを防ぐにはコミットの署名と verify ではないコミットを受け付けないようにする対策が有効。 Git/GitHub 知っておくと便利かも Tips 37
ジョブの通過を必須にする Rules Require a pull request before merging Require status checks to pass Do not require status checks on creation Status checks that are required : GitHub Actions: npm test (Actions のジョブ等を指定) [1] 1. デフォルトブランチが対象なら問題ないが、合流ブランチなどの短命なブランチに対して適用する場合は設定しないとブランチ作成 (push) ができないため、これを有効にしている ↩︎ Git/GitHub 知っておくと便利かも Tips 64
タグ名に semantic versioning を強制 Targets: All tags Restrictions Restrict tag names Tag name , Must match a given regex pattern , ^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1- 9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0- 9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ Git/GitHub 知っておくと便利かも Tips 67