$ ssh-keygen
(いろいろ聞かれるけどすべてEnterで大丈夫)
$ ls ~/.ssh/ #確認
id_rsa id_rsa.pub #この2つのファイルがあれば大丈夫
id_rsa.pubの方が公開鍵id_rsa.pubの中身を貼り付け

plus_stdinを作りましょう
plus_stdin#!/usr/bin/python3
import sys
ans = 0.0
for line in sys.stdin:
ans += float(line)
print(ans)
README.mdがひとつ存在したリポジトリができる
$ git clone <さっきクリップボードにコピーした文字列をペースト>
Cloning into 'robosys202x'...
(略)
Receiving objects: 100% (3/3), done.
$ cd robosys202x/
$ ls -a
. .. .git README.md
plus_stdinを一つ置く$ ls
README.md plus_stdin
git addで記録の対象として選択
$ git add plus_stdin
$ git status #ステージングエリアの確認
ブランチ main
Your branch is up to date with 'origin/main'.
コミット予定の変更点:
(use "git restore --staged <file>..." to unstage)
new file: plus_stdin
git commitでステージングエリアの情報をリポジトリに反映
plus_stdinの記録が残るgit commitで作った1つの記録をコミットと呼ぶ$ git commit -m "Add a command" #git commit -m "何をしたか短く"
[main fa8aab8] Add a command
1 file changed, 8 insertions(+)
create mode 100755 plus_stdin
$ git log -n 1 #最新のコミット1件を表示
commit fa8aab8a2ade8cd33823f488fbb1bbec6d981260 (HEAD -> main)
Author: Ryuichi Ueda <ryuichiueda@gmail.com>
Date: Tue Dec 7 16:58:54 2021 +0900
Add a command
git push$ git push #git push origin mainと打たないといけない場合もある
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 16 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 373 bytes | 373.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To github.com:ryuichiueda/robosys202x.git
68d342f..fa8aab8 main -> main
$ git branch
- main #ブランチはmainだけ.「-」は選択状態を表現
$ git switch -c dev #git checkout -b devでも可
Switched to a new branch 'dev'
$ git branch
- dev #devブランチができて,devが選択状態に
main
ついでにPythonの文法の勉強もします
plus_stdinについて,整数の文字列は整数に変換するよう改良
tryで囲むexceptのブロックを作って例外処理#!/usr/bin/python3
import sys
ans = 0 #もともと0.0だったのを0に変更
for line in sys.stdin:
try:
ans += int(line) #intは文字列を整数に(失敗すると例外発生)
except:
ans += float(line)
print(ans)
###動作確認###
$ seq 5 | ./plus_stdin
15 #整数として処理されていることを確認
$ seq 5 | sed 's/$/.1/' | ./plus_stdin
15.5 #小数も計算できることを確認
###バグがないことを確認したらコミット###
$ git add -A #-Aで変更を全部ステージングできる
$ git status #ブランチと変更されたファイルを確認
ブランチ dev
コミット予定の変更点:
(use "git restore --staged <file>..." to unstage)
modified: plus_stdin
$ git commit -m "Support integer calculation"
[dev f02a202] Support integer calculation
1 file changed, 5 insertions(+), 2 deletions(-)
###不要だけどGitHubにもプッシュしてみましょう###
$ git push --set-upstream origin dev #origin: GitHubにあるリポジトリのこと
(略)
- [new branch] dev -> dev
Branch 'dev' set up to track remote branch 'dev' from 'origin'.
git log --graphで表示してみましょう$ git log --graph #下の出力は一部省略
- commit f02a20237590c9e4650f100928c6c2f969c111c3 (HEAD -> dev, origin/dev)
| Support integer calculation
|
- commit fa8aab8a2ade8cd33823f488fbb1bbec6d981260 (origin/main, origin/HEAD, main)
| Add a command
|
- commit 68d342fbb7a9b65e402d0b6f5a7763e56f248937
Initial commit
f02a2023...のような識別記号HEAD: いまのディレクトリの内容origin/<ブランチ名>: GitHubのリポジトリのブランチ$ git switch main # git checkout mainでも可
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
$ git diff main dev
(略.mainとdevのコードの違いが表示される)
$ git merge dev #下の出力には省略あり
1 file changed, 5 insertions(+), 2 deletions(-)
$ cat plus_stdin
(略.try...exceptの入ったコードが表示される)
$ git push
To github.com:ryuichiueda/robosys202x.git
fa8aab8..f02a202 main -> main
そういう状況を作ってみましょう.
$ mkdir ~/tmp/
$ cd ~/tmp/
$ git clone git@(略) #略の部分は自分で考えましょう
#!/usr/bin/python3
import sys
#スライドの関係で1行だけど、本来、関数の前後は2行空白をあける
def tonum(s): #def 関数の名前(引数)で関数を定義
try:
return int(s)
except:
return float(s)
ans = 0
for line in sys.stdin:
ans += tonum(line)
print(ans)
(略)
for line in sys.stdin:
line = line.rstrip() #for文の下にこの行を挿入
(以下略)
$ git push
To github.com:ryuichiueda/robosys202x
! [rejected] main -> main (non-fast-forward)
error: failed to push some refs to 'git@github.com:ryuichiueda/robosys202x'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
git pull$ git pull #出力には省略あり
CONFLICT (content): Merge conflict in plus_stdin
Automatic merge failed; fix conflicts and then commit the result.
CONFLICT」と出るがpullは完了
plus_stdinの内容(A, B両方の更新が反映されるが矛盾も生じる)(略)
<<<<<<< HEAD #Bの内容
ans = 0
for line in sys.stdin:
line = line.rstrip()
======= #Aの内容
def tonum(s):
>>>>>>> a4936f439aed64b3234d533c6e7a3abc7b5d744d
(以下略)
#!/usr/bin/python3
import sys
#2行あけましょう
def tonum(s):
try:
return int(s)
except:
return float(s)
#2行あけましょう
ans = 0
for line in sys.stdin:
line = line.rstrip()
ans += tonum(line)
print(ans)
$ git log
commit f02a20237590c9e4650f100928c6c2f969c111c3 (HEAD -> main, origin/main, origin/HEAD)
(略)
Support integer calculation
commit fa8aab8a2ade8cd33823f488fbb1bbec6d981260 #これの`plus_stdin`を取り出したい
(略)
Add a command
commit 68d342fbb7a9b65e402d0b6f5a7763e56f248937
(略)
Initial commit
$ git switch -d fa8aab8 #コミットハッシュ値の先頭何桁を指定
HEAD is now at fa8aab8 Add a command
$ git branch
- (HEAD detached at fa8aab8) #使い捨てのブランチができる
dev
main
$ cat plus_stdin
(略.try,exceptを加える前のコード)
$ cp plus_stdin /tmp/ #必要ならコードのコピーをとる
$ git switch - #元に戻る
Previous HEAD position was fa8aab8 Add a command
Switched to branch 'main'
Your branch is up to date with 'origin/main'.
git remote add origin <リポジトリ>で結びつけmasterなのに,リモートがmainのときは手元をmainにするとよい.git/configを編集