
Git 公式リンクから確認しておきたい初心者機能を抽出して、操作の流れに合わせて状態の変化、確認方法をシーケンス図でまとめます。
👉 Git - Reference
👉 とほほのGit入門 - とほほのWWW入門


Git 公式リンクから確認しておきたい初心者機能を抽出して、操作の流れに合わせて状態の変化、確認方法をシーケンス図でまとめます。
👉 Git - Reference
👉 とほほのGit入門 - とほほのWWW入門


なんでこんなに領域の名称があるのか。
歴史的な何かか、日本語の弊害か。
初心者新参者がつまずいたメモです。
{ ワーキング | ワーク | 作業 } [ ツリー | ディレクトリ ]
- ワーキングツリー
- ワーキングディレクトリ
- ワークディレクトリ
- ワークツリー
- 作業ディレクトリ
{ インデックス | ステージ | ステージング } [ エリア | ディレクトリ ]
- インデックス
- ステージング
- ステージ
- ステージングエリア
ローカル [ リポジトリ | ブランチ ]
- ローカルリポジトリ
- ローカルブランチ
リモート [ リポジトリ | ブランチ ]
- リモートリポジトリ
- リモートブランチ
職場環境のポリシーや管理者によって変わったりするんだわ。
WEBで公開されている著名リファレンスやドキュメントでもいろいろ変わる。
狭い環境に依存することなく広く。
各コマンドによる状態変化遷移シーケンス図を次は作ってみたいです。

Git HTTPS Credential Helper がややこしいので SSH に切り替える。
GitHub リポジトリを指す remote origin の変更が必要となりますので、ざっくり概要を見ておきます。
# HTTPS 利用していたとする
git remote -v
> origin https://github.com/OWNER/REPOSITORY.git (fetch)
> origin https://github.com/OWNER/REPOSITORY.git (push)
# SSH 形式の URL に変更
git remote set-url origin [email protected]:OWNER/REPOSITORY.git
# 確認
git remote -v
# Verify new remote URL
> origin [email protected]:OWNER/REPOSITORY.git (fetch)
> origin [email protected]:OWNER/REPOSITORY.git (push)
👉 リモートリポジトリを管理する - GitHub Docs
1. 鍵をPC側で作成。
❯ ssh-keygen -t ed25519 -C [email protected] -f ~/.ssh/id_ed25519_main
👉 新しい SSH キーを生成して ssh-agent に追加する - GitHub Docs
2. GitHub にログインして貼る。Authentication keys
❯ pbcopy < ~/.ssh/id_ed25519_main.pub
3. ~/.ssh/config を設定する。
❯ vi ~/.ssh/config
Host github-main
HostName github.com
User git
Port 22
IdentityFile ~/.ssh/id_ed25519_main
TCPKeepAlive yes
IdentitiesOnly yes # need for multiple accounts
Host github-sub
HostName github.com
User git
Port 22
IdentityFile ~/.ssh/id_ed25519_sub
TCPKeepAlive yes
IdentitiesOnly yes # need for multiple accounts
4. PC側プロジェクト内で remote origin を書き換える。
git@github-main:your-main/Sample.git
❯ git remote -v
origin https://github.com/your-main/Sample.git (fetch)
origin https://github.com/your-main/Sample.git (push)
❯ git remote set-url origin git@github-main:your-main/Sample.git
❯ git remote -v
origin git@github-main:your-main/Sample.git (fetch)
origin git@github-main:your-main/Sample.git (push)
❯ cat .git/config
[remote "origin"]
url = git@github-main:your-main/Sample.git
fetch = +refs/heads/*:refs/remotes/origin/*
5. 接続を確認する。
❯ ssh -T git@github-main
Hi your-main! You've successfully authenticated, but GitHub does not provide shell access.
👉 [備忘] 複数Githubアカウントでssh接続設定(config)を使い分ける手順 #GitHub - Qiita
URL 記述部分は、ssh:// がついてるほうが意味が分かりやすい気がします。
その場合は ~/.ssh/config の port 22 の記述は不要のようですが、
現在 GitHub ではスキーマ部分消えています。

などとダラダラ書きましたが、以下読んでみるとよく分かります。
👉 Multiple GitHub Accounts & SSH Config - Stack Overflow
👉 Using multiple github accounts with ssh keys
👉 【Git】Obsidian を GitHub と連携する
👉 初心者向け Git コマンドと領域の移動をシーケンス図で書いてみた

これ、おもしろい!!
ちょっと画像をお借りして、
やってみましたが、、、
@Composable
fun Humans() {
var currentRotation by remember { mutableFloatStateOf(0f) }
val rotation = remember { Animatable(currentRotation) }
LaunchedEffect(Unit) {
rotation.animateTo(
targetValue = currentRotation + 360f,
animationSpec = infiniteRepeatable(
animation = tween(3000, easing = LinearEasing),
repeatMode = RepeatMode.Restart
)
) {
currentRotation = rotation.value
}
}
Image(
modifier = Modifier
.fillMaxSize()
.rotate(rotation.value)
.aspectRatio(1.0f),
painter = painterResource(R.drawable.humans),
contentDescription = null
)
}
ダメでした。。。

なんで、おじさんが走ってくれないのでしょうかー。

なんか、いろんな方法があるんだなあ、と。
👉 Lifecycle を Compose と統合する | App architecture | Android Developers
👉 ComposeでLifecycleを監視する(2023年9月バージョン) - Kenji Abe - Medium
いろいろ試しながらどこから使っていくのがいいか。を考える。
調べてみると、
DisposableEffect を中心に考えるのがいいだろう、
と思える。
@Composable
fun LifecycleEffect(
onCreate: () -> Unit = { },
onStart: () -> Unit = { },
onResume: () -> Unit = { },
onPause: () -> Unit = { },
onStop: () -> Unit = { },
onDestroy: () -> Unit = { },
onAny: () -> Unit = { }
) {
val lifecycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
when (event) {
Event.ON_CREATE -> onCreate()
Event.ON_START -> onStart()
Event.ON_RESUME -> onResume()
Event.ON_PAUSE -> onPause()
Event.ON_STOP -> onStop()
Event.ON_DESTROY -> onDestroy()
Event.ON_ANY -> onAny()
}
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
}
@Composable
fun LifecycleEffect(
lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current,
onStart: (suspend () -> Unit)? = null,
onPause: (suspend () -> Unit)? = null,
onStop: (suspend () -> Unit)? = null
) {
val scope = rememberCoroutineScope()
val currentOnStart by rememberUpdatedState(onStart)
val currentOnPause by rememberUpdatedState(onPause)
val currentOnStop by rememberUpdatedState(onStop)
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
scope.launch {
when (event) {
Lifecycle.Event.ON_START -> currentOnStart?.invoke()
Lifecycle.Event.ON_PAUSE -> currentOnPause?.invoke()
Lifecycle.Event.ON_STOP -> currentOnStop?.invoke()
else -> {}
}
}
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose {
lifecycleOwner.lifecycle.removeObserver(observer)
}
}
}
@Immutable
enum class LifecycleEvent {
OnStop
}
@Immutable
data class LifecycleHandler(
val id: String,
val event: LifecycleEvent,
val onEvent: () -> Unit
)
@Composable
fun <R : Any> DestinationScope<R>.LifecycleEffect(
event: LifecycleEvent,
onEvent: () -> Unit
) {
val id = remember { randomUUID() }
DisposableEffect(this, id, event, onEvent) {
navigator.update {
it.copy(lifecycleHandlers = it.lifecycleHandlers + LifecycleHandler(
id = id,
event = event,
onEvent = onEvent
))
}
onDispose {
navigator.update { dest ->
dest.copy(lifecycleHandlers = dest.lifecycleHandlers.filter { it.id != id })
}
}
}
}
まずは、ここらから記述していくのがいいのではないか。
@Composable
@NonRestartableComposable
fun DisposableLifecycleEffect(
lifecycle: Lifecycle = LocalLifecycleOwner.current.lifecycle,
onResume: () -> Unit,
onPause: () -> Unit,
) {
DisposableEffect(lifecycle) {
val observer = LifecycleEventObserver { _, event ->
when (event) {
Lifecycle.Event.ON_RESUME -> onResume()
Lifecycle.Event.ON_PAUSE -> onPause()
else -> { }
}
}
lifecycle.addObserver(observer)
onDispose {
lifecycle.removeObserver(observer)
}
}
}
記述位置は Screen。
@NonRestartableComposable の意味を考えながら書く。
フォアグラウンド、バックグラウンドの切り分けにも使えるか。