Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

このリポジトリに対するコントリビューションの手順をまとめる #6

Open
terasakisatoshi opened this issue Mar 7, 2024 · 12 comments

Comments

@terasakisatoshi
Copy link
Member

terasakisatoshi commented Mar 7, 2024

手順をまとめる

ほとんどの人は https://github.com/AtelierArith/OkinawaCompPhysFoodSurvey2024.jl.git に対して書き込み権限を持っていない.そのため,編集をするには Fork を行ってリポジトリをコピーする.

コピーしたリポジトリには各自に書き込み権限が付与されるのでそれに対して追加修正を行う.

そのあとプルリクエストを送り https://github.com/AtelierArith/OkinawaCompPhysFoodSurvey2024.jl.git に対して変更を要請する.

image
@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

このリポジトリを Fork をする

https://github.com/AtelierArith/OkinawaCompPhysFoodSurvey2024.jl

画面右上にある Fork のボタンをクリックする

image

下記の画面に遷移する.
緑色の Create fork ボタンを押す

image

Create fork ボタンを押すと AtelierArith/OkinawaCompPhysFoodSurvey2024.jl がコピーされて <your-gh-name>/OkinawaCompPhysFoodSurvey2024.jl ができる.

image

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

<your-gh-name>/OkinawaCompPhysFoodSurvey2024.jl.git をクローン

以後の注意

<your-gh-name> の部分は各自の GitHub アカウント名として読み替えてください.

私 (@terasakisatoshi ) の場合は <your-gh-name> の部分を terasakisatoshi と置き換えて <your-gh-name>/OkinawaCompPhysFoodSurvey2024.jl.gitterasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl.git と命名します.

クローンの仕方

ローカル環境の作業ディレクトリを決める

ローカル環境とは皆さんの手元のパソコンのことである.今後「ローカル環境にインストールしてください」という言葉は「自分のパソコンに対象のソフトウェアやドキュメントなどをダウンロード・インストールすること」と理解すれば良い.

以後作業ディレクトリは ~/work を前提とする.~ はホームディレクトリを指す.実のところ,各自の慣れている作業ディレクトリで作業を行えば良い.

$ cd ~ # 一旦ホームディレクトリに移動
$ mkdir work # 実際はどこでも良い.各自の作業スペースにクローンすれば良い
$ cd work # ~/work に移動

クローンをする対象の URL をコピーする

https://github.com/<your-gh-name>/OkinawaCompPhysFoodSurvey2024.jl にアクセス.

下記画面の <> Code という緑色のボタンを押す

image

押すと次のような画面が見える

image

Copy url to clipboard でリンクをコピーできる.

私の場合は下記の文字列がコピーされる.

git@github.com:terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl.git

(セキュリティの強化で二要素認証をされている方は SSH の方を選択する. 上記のスクリーンショットのように忠実に操作していれば問題ない)

ローカル環境にクローンする

クローンはソースコード.バージョン履歴を含めた情報を手元にダウンロードすると読み替えれば良い.

いよいよローカル環境にクローンする.先ほどコピーしたURLを元に下記のコマンドを実行する

$ cd work # ~/work に移動
$ git clone git@github.com:<your-gh-account>/OkinawaCompPhysFoodSurvey2024.jl.git # これはコピペするな!!!
Cloning into 'OkinawaCompPhysFoodSurvey2024.jl'...
remote: Enumerating objects: 220, done.
remote: Counting objects: 100% (220/220), done.
remote: Compressing objects: 100% (110/110), done.
remote: Total 220 (delta 87), reused 206 (delta 76), pack-reused 0
Receiving objects: 100% (220/220), 43.63 KiB | 269.00 KiB/s, done.
Resolving deltas: 100% (87/87), done.
$ ls OkinawaCompPhysFoodSurvey2024.jl

最後に OkinawaCompPhysFoodSurvey2024.jl に移動する

$ cd OkinawaCompPhysFoodSurvey2024.jl
$ pwd
<各自のホームディレクトリ>/work/OkinawaCompPhysFoodSurvey2024.jl
$ ls
LICENSE        Project.toml   formatcheck.jl src
Makefile       README.md      interactive.jl test
Manifest.toml  docs           poll           tools

以後この場所をリポジトリへのパス
という意味で path/to/repository という言い方をすることがある.例えば次のような表記をする

$ cd path/to/repository
$ ls 
LICENSE        Project.toml   formatcheck.jl src
Makefile       README.md      interactive.jl test
Manifest.toml  docs           poll           tools

また ls -a によって 書くしファイル,隠しディレクトリが見える. 特に .git というのがあることに注意する:

$ ls -a
ls -a
.                    LICENSE              interactive.jl
..                   Makefile             poll
.JuliaFormatter.toml Manifest.toml        src
.devcontainer        Project.toml         test
.git                 README.md            tools
.github              docs
.gitignore           formatcheck.jl

.git に変更履歴などが格納される.これを間違って消すと履歴が消えるので注意.

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

OkinawaCompPhysFoodSurvey2024.jl に対して変更を加える

その前にローカル環境の GIt 設定を設定・確認する

$ cd path/to/repository # クローンをしたリポジトリへのパスだったね!
$ git config --local github.user <your-gh-name>

例えば私 (@terasakisatoshi) の場合は

$ git config --local github.user terasakisatoshi

のように設定している.

設定が反映されているかは下記のようにして確認ができる

$ pwd
~/work/OkinawaCompPhysFoodSurvey2024.jl # path/to/repository
$ ls -a
.                    LICENSE              interactive.jl
..                   Makefile             poll
.JuliaFormatter.toml Manifest.toml        src
.devcontainer        Project.toml         test
.git                 README.md            tools
.github              docs
.gitignore           formatcheck.jl
$ cat .git/config
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"]
	url = git@github.com:terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
	remote = origin
	merge = refs/heads/main
[github]
	user = terasakisatoshi # この部分を確認する

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

ブランチを作成する

注意: main (デフォルトブランチには直接コミットしない!!!必ずブランチを作る)

バージョン履歴は前の変更と今回する変更の差分の系列によって管理されている.この系列を GIt では branch, ブランチと呼んでいる.共同開発においては main を共用のブランチ(取り込み先)として使うので main ブランチに直接変更履歴を追加してはいけない.

注意: main (デフォルトブランチには直接コミットしない!!!必ずブランチを作る)

<your-gh-name>/okinawa-food という名前のブランチを作成する

$ git switch -c <your-gh-name>/okinawa-food

例えば私 @terasakisatoshi の場合は次のようにする.適切に各自の環境に応じて読み替えてください.

$ git switch -c terasakisatoshi/okinawa-food # これはコピペするな!!!

Tips

checkout -b によってブランチを作っても良い.ただ,switch -c を使うのが現代的らしい.git checkout を使うと変更した変更の取り消しの役割もあるのでブランチ名とファイル名が一致していると意図しない結果を生む可能性がある.

$ git checkout -b terasakisatoshi/okinawa-food # まぁこれでもよい
$ # 実際に自分も手癖でタイプしてしまうので...

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

interactive.jl を使って沖縄料理をサジェストする

以下,特に断りがない限り作業ディレクトリは path/to/repository とする.すなわち下記のような状態になっていると仮定する:

$  pwd
~/work/OkinawaCompPhysFoodSurvey2024.jl # path/to/repository

Julia プロジェクトのセットアップ

すでに Julia がインストールされているとする.

下記を実行する:

$ julia -e 'using Pkg; Pkg.activate("."); Pkg.instantiate()'

これでプロジェクトのセットアップができる.

-e が使えない環境の場合,一旦 julia によって REPL を起動し下記を実行する

$ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.2 (2024-03-01)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> using Pkg; Pkg.activate("."); Pkg.instantiate()
    Updating registry at `~/.julia/registries/General.toml`
    Updating `~/work/OkinawaCompPhysFoodSurvey2024.jl/Project.toml`
  [a93c6f00] + DataFrames v1.6.1
  [fa267f1f] ~ TOML ⇒ v1.0.3
    Updating `~/work/OkinawaCompPhysFoodSurvey2024.jl/Manifest.toml`
  [34da2185] + Compat v4.14.0
  [a8cc5b0e] + Crayons v4.1.1
  [9a962f9c] + DataAPI v1.16.0
  [a93c6f00] + DataFrames v1.6.1
  [864edb3b] + DataStructures v0.18.18
  [e2d170a0] + DataValueInterfaces v1.0.0
  [842dd82b] + InlineStrings v1.4.0
  [41ab1584] + InvertedIndices v1.3.0
  [82899510] + IteratorInterfaceExtensions v1.0.0
  [b964fa9f] + LaTeXStrings v1.3.1
  [e1d29d7a] + Missings v1.1.0
  [bac558e1] + OrderedCollections v1.6.3
  [69de0a69] + Parsers v2.8.1
  [2dfb63ee] + PooledArrays v1.4.3
  [aea7be01] + PrecompileTools v1.2.0
  [21216c6a] + Preferences v1.4.3
  [08abe8d2] + PrettyTables v2.3.1
  [189a3867] + Reexport v1.2.2
  [91c51154] + SentinelArrays v1.4.1
  [a2af1166] + SortingAlgorithms v1.2.1
  [892a3eda] + StringManipulation v0.3.4
  [3783bdb8] + TableTraits v1.0.1
  [bd369af6] + Tables v1.11.1
  [56f22d72] + Artifacts
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [9fa8497b] + Future
  [b77e0a4c] + InteractiveUtils
  [76f85450] + LibGit2
  [8f399da3] + Libdl
  [37e2e46d] + LinearAlgebra
  [d6f4376e] + Markdown
  [ca575930] + NetworkOptions v1.2.0
  [de0858da] + Printf
  [3fa0cd96] + REPL
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [6462fe0b] + Sockets
  [2f01184e] + SparseArrays v1.10.0
  [10745b16] + Statistics v1.10.0
  [fa267f1f] + TOML v1.0.3
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [e66e0078] + CompilerSupportLibraries_jll v1.1.0+0
  [e37daf67] + LibGit2_jll v1.6.4+0
  [29816b5a] + LibSSH2_jll v1.11.0+1
  [c8ffd9c3] + MbedTLS_jll v2.28.2+1
  [4536629a] + OpenBLAS_jll v0.3.23+4
  [bea87d4a] + SuiteSparse_jll v7.2.1+1
  [8e850b90] + libblastrampoline_jll v5.8.0+1
julia> exit() # これで終了する

interactive.jl でテンプレートを生成する

$ julia --project interactive.jl
julia --project interactive.jl
[ Info: githubuser=terasakisatoshi
Choose your favorite okinawa food:
# 上下の矢印キーで選択できます.とりあえず選んでください.
 > 沖縄そば
   ヤギの刺身
   ミミガー
   黒糖
# 上下の矢印キーで選択できます.とりあえず選んでください.
   沖縄そば
> ヤギの刺身 # ヤギの刺身が面白かったので今回はこれを選びます
   ミミガー
   黒糖
Your favorite food is ヤギの刺身!
[ Info: tomlfile=poll/<your-gh-account>/food/Data.toml has been created

下記のようにして Data.toml の中身を確認します.

$ cat poll/<your-gh-account>/food/Data.toml
food = ["ヤギの刺身"]

各自の好みの問題で編集をしたければテキストエディタを開いて下記のように設定しても良い.

food = ["黒糖アメ", "沖縄そば"]

フォーマットチェック

Data.toml が適切なものになっているかを確認する.

$ julia --project formatcheck.jl
[ Info: githubuser=terasakisatoshi
[ Info: Your tomlfile=poll/terasakisatoshi/food/Data.toml is valid. Go on to the next step

特に問題がなければ先に進む

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

コミットをする

現在の状態を git status コマンドで確認する.

$ git status
On branch terasakisatoshi/okinawa-food
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	poll/terasakisatoshi/

nothing added to commit but untracked files present (use "git add" to track)

On branch main になってたらマズイので

$ git switch -c <your-gh-name>/okinawa-food

のようにブランチを作ってくださいね!

ステージング領域にファイルを作る

ステージング領域(staging area)にコミットをする対象を格納する.

$ git add poll/terasakisatoshi/food/Data.toml

add の取り消しは git restore --staged path/to/target/file によって行います.

$ git restore --staged poll/terasakisatoshi/food/Data.toml

Git コマンドだけだと操作が難しいので tig を使うと便利です.

コミットをする

いよいよコミットをする git commit -m "<変更内容>" のように利用する.今回の場合は

$ git commit -m "Add Data.toml"

にようにすればよいだろう.

必要に応じて下記のように各自の名前・メールアドレスを設定すること

$ git config --local user.name "John Doe"
$ git config --local user.email johndoe@example.com

これらの情報は「誰が変更したか」を後から他の人が知るためにバージョン履歴として保存される.

https://git-scm.com/book/ja/v2/%E4%BD%BF%E3%81%84%E5%A7%8B%E3%82%81%E3%82%8B-%E6%9C%80%E5%88%9D%E3%81%AEGit%E3%81%AE%E6%A7%8B%E6%88%90

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

VS Code で作業をする場合

ぬぁーーーー.ターミナル嫌いーーーーー.いやダァーーーーー.と焦ってる人向け

$ cd path/to/repository
$ code .

のようにすると VS Code で作業ができる.

image

サイドバーにある枝のようなアイコンをクリックする.これで Git の操作をグラフィカルに操作ができる.

image

ステージング領域に追加

image

ステージング領域に追加したいものを選択する.今回の場合は Data.toml をクリックする.

このようにすると Data.toml の差分が表示される.左側の赤色のゾーンが変更前,緑色が変更後の内容である.画像のスクリーンショットでは food = ["ヤギの刺身"] を変更した場合のものである.

image

緑色の領域で右クリックをし Stage Selected Ranges を押す.

image

Stage Selected Ranges の変更をキャンセルするためには VS Code 左側にある - マイナス記号のようなアイコンをクリックする.Unstage Changes をクリックする.

image

Commit

コミットする場合は下記のようにメッセージを入力してから Commit ボタンを押す.これで git commit -m "Add Data.toml" に相当する作業ができる.

image

@terasakisatoshi
Copy link
Member Author

コミットメッセージ考えるのめんどいんじゃーー

という場合は AI の力を借りるのも手.直しAPI を利用する都合上何かしらお金を払う必要がある.例えば aicommits, や Copilot を使う手がある.

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

プッシュする

ローカルの変更を各自が管理しているリモートリポジトリにプッシュする.プッシュする先のリモートリポジトリは Fork によって元のリポジトリをコピーしたURLになっている.

例えば私の場合は git@github.com:terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl.git である.

これを確認するには下記のようにすればよい:

$ git remote get-url origin
git@github.com:terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl.git # 各自の環境に依存する

ローカル環境で行った変更・ブランチをリモートリポジトリに対してプッシュする

$ git push origin terasakisatoshi/okinawa-food

このようにするとリモートリポジトリにブランチが作られる.

$ git push origin terasakisatoshi/okinawa-food
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'terasakisatoshi/okinawa-food' on GitHub by visiting:
remote:      https://github.com/terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl/pull/new/terasakisatoshi/okinawa-food
remote:
To github.com:terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl.git
 * [new branch]      terasakisatoshi/okinawa-food -> terasakisatoshi/okinawa-food

Fork した各自のリポジトリにリモートブランチが作られる.

image

プッシュができるのはプッシュを行ったユーザが書き込み権限を与えられている場合である.なので,受講者は変更をプッシュするために書き込みできるリモートリポジトリを用意する必要があった.それが Fork する行為であった.

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

プルリクエストを作って本家にマージしてもらう

https://github.com/terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl などのリポジトリはオリジナルの https://github.com/AtelierArith/OkinawaCompPhysFoodSurvey2024.jl をコピーしたものである.

各自の変更を本家 https://github.com/AtelierArith/OkinawaCompPhysFoodSurvey2024.jl に取り込もう.

プルリクエストを送る

各自のリモートリポジトリに移動し Pull requests をクリックする.

image

下記のような画面に遷移する.画面の右側にある New pull request をクリックする.

image

下記のようにしてプルリクエストを作る.

image

@terasakisatoshi
Copy link
Member Author

しばらく待つ

黄色の円がぐるぐる動きます.しばらく待ちます.

image

あとは私が頑張ってチェックします.

@terasakisatoshi
Copy link
Member Author

terasakisatoshi commented Mar 7, 2024

マージ後の作業

リモートリポジトリの main ブランチを更新

Git 分散型なので各自のリポジトリの main は常に同一の履歴を指しているわけではありません.https://github.com/AtelierArith/OkinawaCompPhysFoodSurvey2024.jl.git の main を追従する必要があります.

受講者は変更を fork したリポジトリに再び取り込みます.この操作は GitHub でできます.

各自のフォークしたリポジトリに移動します.

image

This branch is [6 commits behind](https://github.com/terasakisatoshi/OkinawaCompPhysFoodSurvey2024.jl/compare/main...AtelierArith%3AOkinawaCompPhysFoodSurvey2024.jl%3Amain) AtelierArith/OkinawaCompPhysFoodSurvey2024.jl:main. のようなメッセージの付近にある Sync fork ボタンを押します.

Update branch ボタンを押します.

image

ローカル環境のブランチを更新

下記のようにします.

$ git checkout main
$ git pull origin main

これで(この瞬間においては)リモートリポジトリの main ブランチとローカル環境のmain が同期されました.

お疲れ様でした!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant