uetennis’s diary

プログラミングについて学んだ事やライフハックについてかきます

5/7 LTの準備の集中

5/7 LTの準備の集中

目標・やりたい事は何か?何に興味あるか?

LT

  • 発表の情報を箇条書きでメモ
  • Googleスライドの勉強
  • 構成考える

日常メモ・ちょっとした事・何を感じたか?

  • Vscodeの配色テーマ!ソラタイズライトは目に優しい

何を学んだか?・何がまだ理解できてないのか?

  • Git commit を戻す時はオプションにきをつける。

勉強メモ

リモートリポジトリにクローンする

git clone <repository> <directory>

(m・_・bp) mbp-2 14:03 ~/Desktop/vsnote % git clone https:/xxxxxxxxxx.com/git/AAA/tutorial.git tutorial2
Cloning into 'tutorial2'...
Username for 'https://xxxxxxx.com': xxxxxxx.com   #メールアドレス
Password for 'https://xxxxxxxxxx.xxxxxx.com':   #パスワード
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (6/6), 617 bytes | 102.00 KiB/s, done.

(m・_・bp) mbp-2 14:04 ~/Desktop/vsnote % ls tutorial2
sample.txt
(m・_・bp) mbp-2 14:05 ~/Desktop/vsnote % cat tutorial2/sample.txt
git is good
tutorial add

クローンしたリポジトリからプッシュする

(m・_・bp) mbp-2 14:28 ~/Desktop/vsnote % cd tutorial2
(m・_・bp) mbp-2 14:30 ~/Desktop/vsnote/tutorial2 % vi sample.txt
(m・_・bp) mbp-2 14:31 ~/Desktop/vsnote/tutorial2 % cat sample.txt
git is good
tutorial add
abc
(m・_・bp) mbp-2 14:31 ~/Desktop/vsnote/tutorial2 % git add sample.txt
(m・_・bp) mbp-2 14:31 ~/Desktop/vsnote/tutorial2 % git commit -m "abc追加"
[master 5ee0c24] abc追加
 1 file changed, 1 insertion(+)
(m・_・bp) mbp-2 14:32 ~/Desktop/vsnote/tutorial2 % git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 285 bytes | 285.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://uetennis.backlog.com/git/AAA/tutorial.git
   3830d53..5ee0c24  master -> master


リモートリポジトリからプルする

git pull <repository> <refspec>...

(m・_・bp) mbp-2 14:42 ~/Desktop/vsnote/tutorial2 % cd
(m・_・bp) mbp-2 14:42 ~ % cd tutorial
(m・_・bp) mbp-2 14:42 ~/tutorial % git pull origin master
remote: Enumerating objects: 5, done.
remote: Counting objects:  80% (4/5)
remote: Counting objects: 100% (5/5), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), 342 bytes | 171.00 KiB/s, done.
From cccccccc.git.backlog.com:/AAA/tutorial
 * branch            master     -> FETCH_HEAD
   3830d53..5ee0c24  master     -> origin/master
Auto-merging sample.txt
CONFLICT (content): Merge conflict in sample.txt
Automatic merge failed; fix conflicts and then commit the result.
(m・_・bp) mbp-2 14:43 ~/tutorial % gitlog
zsh: command not found: gitlog
(m・_・bp) mbp-2 14:44 ~/tutorial %  git log
commit 39726fbf00a71b70e22aba247b2e5159fdf6a677 (HEAD -> master)
Author: xxxxxxxx
Date:   Tue May 5 17:44:33 2020 +0900

    commitの内容追加

commit 3830d532db6b0c4dfd748f98ef3adbaa9701c73f
Author: xxxxxxxxxxxx
Date:   Tue May 5 16:16:31 2020 +0900

    addの説明を追加

commit 6b32dd2d7d53ffb2b0eb7001fa37ba5842d16c39
Author: xxxxxxxxxxxx
Date:   Mon May 4 16:39:23 2020 +0900

    <first commit>
(m・_・bp) mbp-2 14:44 ~/tutorial % cat sample.txt
git is good
tutorial add
<<<<<<< HEAD
commit    wow
=======
abc
>>>>>>> 5ee0c24ccadac0c6d7c924af19f8a1bf6c377407
(m・_・bp) mbp-2 14:44 ~/tutorial %

競合状態からプッシュ

(m・_・bp) mbp-2 15:07 ~ % cd tutorial
(m・_・bp) mbp-2 14:44 ~/tutorial % cat sample.txt
git is good
tutorial add
<<<<<<< HEAD
commit    wow
=======
abc
>>>>>>> xxxxxxxxxxxxxxxxxxxx
(m・_・bp) mbp-2 14:44 ~/tutorial %

# 編集する。マーカー行を削除
(m・_・bp) mbp-2 15:07 ~/tutorial % vi sample.txt
(m・_・bp) mbp-2 15:14 ~/tutorial % cat sample.txt
git is good
tutorial add
commit    wow
abc

(m・_・bp) mbp-2 15:14 ~/tutorial % git add sample.txt

(m・_・bp) mbp-2 15:15 ~/tutorial % git commit -m "マージ"
[master 814f2e2] マージ
#履歴の流れを表示する。` --graph`コミットの情報を一行で表示`--oneline`
(m・_・bp) mbp-2 15:16 ~/tutorial % git log --graph --oneline
*   814f2e2 (HEAD -> master) マージ
|\
| * 5ee0c24 (origin/master) abc追加
* | 39726fb commitの内容追加
|/
* 3830d53 addの説明を追加
* 6b32dd2 <first commit>

ブランチの準備

(m・_・bp) mbp-2 15:33 ~ % mkdir nekosan
(m・_・bp) mbp-2 15:33 ~ % cd nekosan
(m・_・bp) mbp-2 15:33 ~/nekosan % git init
Initialized empty Git repository in /Users/username/nekosan/.git/
(m・_・bp) mbp-2 15:34 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 15:36 ~/nekosan % cat nekofile.txt
nekosan no git
(m・_・bp) mbp-2 15:36 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 15:37 ~/nekosan % git commit -m "first commit"
[master (root-commit) 852b84e] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 nekofile.txt

ブランチの作成

$ git branch <branchname>

#issue1という名前でブランチを作成
(m・_・bp) mbp-2 16:14 ~/nekosan % git branch issue1
#引数を指定せずにbranchコマンドを実行すると、ブランチの一覧を表示することができる。頭に * のついているのが現在のブランチ
(m・_・bp) mbp-2 16:15 ~/nekosan % git branch
  issue1
* master

ブランチを切り替える

  • 新しく作成したissue1ブランチにコミットを追加していくには、issue1ブランチをチェックアウトする必要がある
  • $ git checkout <branch>
(m・_・bp) mbp-2 16:29 ~/nekosan % git checkout issue1
Switched to branch 'issue1'
(m・_・bp) mbp-2 16:29 ~/nekosan % ls
nekofile.txt
(m・_・bp) mbp-2 16:33 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 16:34 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
(m・_・bp) mbp-2 16:34 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 16:34 ~/nekosan % git commit -m "addの説明追加"
[issue1 c7aac2d] addの説明追加
 1 file changed, 1 insertion(+)
  • checkoutコマンドに -b オプションを指定して実行すると、ブランチの作成とチェックアウトをまとめて行うことができる
  • $ git checkout -b <branch>

ブランチをマージする

  • issue1ブランチに行った変更をmasterブランチに統合
  • mergeコマンド
  • $ git merge <commit>指定したブランチがHEADの指しているブランチに取り込まれる。
#masterブランチに移動
(m・_・bp) mbp-2 16:41 ~/nekosan % git checkout master
Switched to branch 'master'
(m・_・bp) mbp-2 16:41 ~/nekosan % cat nekofile.txt
nekosan no git
#mergeで取り込む
(m・_・bp) mbp-2 16:42 ~/nekosan % git merge issue1
Updating 852b84e..c7aac2d
Fast-forward
 nekofile.txt | 1 +
 1 file changed, 1 insertion(+)

(m・_・bp) mbp-2 16:43 ~/nekosan % cat nekofile.txt
nekosan no git
neko add

ブランチを削除する

  • issue1ブランチの内容はmasterに統合されたので削除
  • $ git branch -d <branchname>
(m・_・bp) mbp-2 17:01 ~/nekosan % git branch
  issue1
* master
(m・_・bp) mbp-2 17:01 ~/nekosan % git branch -d issue1
Deleted branch issue1 (was c7aac2d).
(m・_・bp) mbp-2 17:02 ~/nekosan % git branch
* master

並行で作業する

#issue2ブランチとissue3ブランチを作成
(m・_・bp) mbp-2 17:02 ~/nekosan % git branch issue2
(m・_・bp) mbp-2 17:11 ~/nekosan % git branch issue3
#issue2ブランチをチェックアウト
(m・_・bp) mbp-2 17:11 ~/nekosan % git checkout issue2
Switched to branch 'issue2'
(m・_・bp) mbp-2 17:12 ~/nekosan % git branch
* issue2
  issue3
  master

(m・_・bp) mbp-2 17:14 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 17:15 ~/nekosan % git commit -m nekofile.txt #間違え
[issue2 7e4c0c4] nekofile.txt
 1 file changed, 1 insertion(+)
(m・_・bp) mbp-2 17:15 ~/nekosan % git commit -m "commitの説明"
On branch issue2
nothing to commit, working tree clean
(m・_・bp) mbp-2 17:16 ~/nekosan % git reset --hard HEAD^ #間違え
HEAD is now at c7aac2d addの説明追加
(m・_・bp) mbp-2 17:17 ~/nekosan % git commit -m "commitの説明"
On branch issue2
nothing to commit, working tree clean
(m・_・bp) mbp-2 17:18 ~/nekosan % git reset --soft HEAD^   #直前の`git commit`の実行を取り消す
(m・_・bp) mbp-2 17:18 ~/nekosan % git commit -m "commitの説明"
[issue2 f4056e1] commitの説明
 1 file changed, 1 insertion(+)
#進めたらmergeできないから作り直し
(m・_・bp) mbp-2 17:52 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 17:54 ~/nekosan % git add
Nothing specified, nothing added.
hint: Maybe you wanted to say 'git add .'?
hint: Turn this message off by running
hint: "git config advice.addEmptyPathspec false"
(m・_・bp) mbp-2 17:54 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 17:54 ~/nekosan % git commit -m "commotの説明追加"
[issue2 f07e6ca] commotの説明追加
 1 file changed, 1 insertion(+)
(m・_・bp) mbp-2 17:55 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
neko commit
#issue3
(m・_・bp) mbp-2 17:20 ~/nekosan % git checkout issue3
Switched to branch 'issue3'
(m・_・bp) mbp-2 17:21 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
(m・_・bp) mbp-2 17:22 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 17:22 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
neko pull
(m・_・bp) mbp-2 17:22 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 17:22 ~/nekosan % git commit -m "pullの説明"
[issue3 1ae506c] pullの説明
 1 file changed, 1 insertion(+)

マージでの衝突を解決する...失敗

  • issue2ブランチでの変更と、issue3ブランチでの変更をmasterに統合
#masterブランチをチェックアウトした後、issue2ブランチをマージ
(m・_・bp) mbp-2 19:16 ~/nekosan %  git checkout master
Already on 'master'
(m・_・bp) mbp-2 19:16 ~/nekosan % git merge issue2
Auto-merging nekofile.txt
CONFLICT (content): Merge conflict in nekofile.txt
Automatic merge failed; fix conflicts and then commit the result. #自動マージ失敗
#確認
(m・_・bp) mbp-2 19:20 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
<<<<<<< HEAD
=======
neko commit
>>>>>>> issue2

(m・_・bp) mbp-2 19:25 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 19:25 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
neko commit
(m・_・bp) mbp-2 19:26 ~/nekosan % git merge issue2
error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
#改めてコミット
(m・_・bp) mbp-2 19:26 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 19:27 ~/nekosan % git commit -m "issue2ブランチをマージ"
[master 0956b72] issue2ブランチをマージ
(m・_・bp) mbp-2 19:28 ~/nekosan % git merge issue2
Already up to date.  #すでに最新状態
#issue3をmerge
(m・_・bp) mbp-2 19:33 ~/nekosan % git merge issue3
Auto-merging nekofile.txt
CONFLICT (content): Merge conflict in nekofile.txt
Automatic merge failed; fix conflicts and then commit the result.
(m・_・bp) mbp-2 19:33 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
<<<<<<< HEAD
neko commit
=======
neko pull
>>>>>>> issue3

(m・_・bp) mbp-2 19:34 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 19:35 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
neko commit
neko pull
(m・_・bp) mbp-2 19:36 ~/nekosan % git commit -m "issue3"
[master ce979da] issue3
(m・_・bp) mbp-2 19:37 ~/nekosan % git status
On branch master
nothing to commit, working tree clean
(m・_・bp) mbp-2 19:43 ~/nekosan % git merge issue3
Already up to date.

rebaseでマージする、、、失敗

  • マージを取り消す
  • $ git reset --hard HEAD~
#issue3ブランチをチェックアウトしてから、masterに対してrebaseを実行
(m・_・bp) mbp-2 19:58 ~/nekosan % git reset --hard HEAD~
HEAD is now at 0956b72 issue2ブランチをマージ
(m・_・bp) mbp-2 20:06 ~/nekosan % git checkout issue3
Switched to branch 'issue3'

(m・_・bp) mbp-2 20:08 ~/nekosan % git rebase master
Auto-merging nekofile.txt
CONFLICT (content): Merge conflict in nekofile.txt
error: could not apply 1ae506c... pullの説明
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply 1ae506c... pullの説明
(m・_・bp) mbp-2 20:10 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
<<<<<<< HEAD
neko commit
=======
neko pull
>>>>>>> 1ae506c... pullの説明
#競合状態だから編集
(m・_・bp) mbp-2 20:12 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 20:12 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
neko commit
neko pull
#rebaseの場合、競合箇所を修正した後はコミットではなく、rebaseコマンドに --continue オプションを指定して実行
#もし、rebase自体を取り消す場合は --abort オプションを指定


git atatus -s

(m・_・bp) mbp-2 20:23 ~/nekosan % cat nekofile.txt
nekosan no git
neko add
neko commit
neko pull
(m・_・bp) mbp-2 20:23 ~/nekosan % git rebase master
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
        git rebase (--continue | --abort | --skip)
If that is not the case, please
        rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.

(m・_・bp) mbp-2 20:24 ~/nekosan % vi nekofile.txt
(m・_・bp) mbp-2 20:25 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 20:25 ~/nekosan % git rebase --continue
hint: Waiting for your editor to close the file... error: There was a problem with the editor 'vi'.
Please supply the message using either -m or -F option.
error: could not commit staged changes.
(m・_・bp) mbp-2 20:26 ~/nekosan % git checkout master
M       nekofile.txt
Switched to branch 'master'
(m・_・bp) mbp-2 20:27 ~/nekosan % git branch
  issue2
  issue3
* master
(m・_・bp) mbp-2 20:29 ~/nekosan % git checkout
M       nekofile.txt
(m・_・bp) mbp-2 20:30 ~/nekosan % git branch -r
(m・_・bp) mbp-2 20:40 ~/nekosan % git branch -r -
fatal: The -a, and -r, options to 'git branch' do not take a branch name.
Did you mean to use: -a|-r --list <pattern>?
(m・_・bp) mbp-2 20:40 ~/nekosan % git branch
  issue2
  issue3
* master
(m・_・bp) mbp-2 20:41 ~/nekosan % git status -s
M  nekofile.txt
(m・_・bp) mbp-2 20:52 ~/nekosan % git add nekofile.txt
(m・_・bp) mbp-2 20:53 ~/nekosan % git status -s
M  nekofile.txt
(m・_・bp) mbp-2 20:53 ~/nekosan % git commit -m "bbb"
[master ba9150f] bbb
 1 file changed, 1 insertion(+)
(m・_・bp) mbp-2 20:53 ~/nekosan % git status -s

参考URL 

  1. サル先生のGit入門
  2. git