imshota / system_development_project_application_1

講義用
0 stars 0 forks source link

Github_PullRequest_first #4

Open imshota opened 3 years ago

imshota commented 3 years ago

演習1 作業記録

cloneのやり方

% git clone リポジトリのパス   ディレクトリ

リポジトリをディレクトリに複製することができる。

実際にやってみる。

% git clone ../Git/myproj cloned
Cloning into 'cloned'...
done.
% cd cloned

リモートリポジトリの一覧を表示する。

% git remote -v
origin  /Users/shota/Documents/tsclass/プログラム応用開発/Github_pull_request/../Git/myproj (fetch)
origin  /Users/shota/Documents/tsclass/プログラム応用開発/Github_pull_request/../Git/myproj (push)
imshota commented 3 years ago

演習2 作業記録

push : リモートに変更を送る fetch : リモートから変更を取ってくる pull : fetch + merge

git fetch refs/remotes/... を更新 + FETCH_HEADを設定

現在のリモートリポジトリからbarを消す

% cd myproj
% ls
bar     foo
% rm foo
% git add foo
% git commit -m "delete foo"
[main a0f877f] delete foo
 1 file changed, 3 deletions(-)
 delete mode 100644 foo

クローンした場所からpull

% cd cloned
% ls
bar     foo
% git pull origin main  
From /Users/shota/Documents/tsclass/プログラム応用開発/Github_pull_request/../Git/myproj
 * branch            main       -> FETCH_HEAD
Removing foo
Merge made by the 'recursive' strategy.
 foo | 3 ---
 1 file changed, 3 deletions(-)
 delete mode 100644 foo
% ls
bar

クローンリポジトリでfooを追加してcommit

% echo baybay > foo
% ls
bar     foo
% git add foo
% git commit -m "add foo"
[master 42097a7] add foo
 1 file changed, 1 insertion(+)
 create mode 100644 foo

pushする。

% git push origin master
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 265 bytes | 265.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To /Users/shota/Documents/tsclass/プログラム応用開発/Github_pull_request/../Git/myproj
   1cb3549..42097a7  master -> master
% cd ../../Git/myproj
% git checkout master
% ls
bar     foo
% cat foo
baybay
imshota commented 3 years ago

演習3 作業記録

リモートリポジトリでjoyファイルを追加

% echo hello > joy
% git add joy
% git commit -m "add joy"
[master 008a25a] add joy
 1 file changed, 1 insertion(+)
 create mode 100644 joy

クローンリポジトリでfetchしてマージ

% git fetch origin
% git merge FETCH_HEAD                 
Updating 42097a7..008a25a
Fast-forward
 joy | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 joy

ログを見てみると直線

% git log --graph --all --decorate=full
* commit 008a25a183c55bd6edd8072e6a6b8ff0f46ad292 (HEAD -> refs/heads/master, refs/remotes/origin/master)
| Author: imshota <imshotaseo@icloud.com>
| Date:   Fri Nov 6 00:30:25 2020 +0900
| 
|     add joy
| 
* commit 42097a771d4ed11eb66c0dda7d3f4e9932b5a7bd
| Author: imshota <imshotaseo@icloud.com>
| Date:   Thu Nov 5 23:49:55 2020 +0900
| 
|     add foo
|   

両方のリポジトリを変更

それぞれのリポジトリでファイルを追加

% echo clcl > cloneside
% git add cloneside
% git commit -m "add cloneside
% cd ../../Git/myproj
% echo reprep > repside
% git add repside 
% git commit -m "add repside" 

クローンリポジトリでfetchしてマージ

% cd ../../Github_pull_request/cloned  
% git fetch origin
% git merge FETCH_HEAD
% git commit -m "merge rep"
[master cdac604] merge rep

ログを見てみると、ブランチが分かれている。

% git log --graph --all --decorate=full
*   commit cdac604d8293a9b0e6fbecc7400003f70fc15ab1 (HEAD -> refs/heads/master)
|\  Merge: fc6e6d4 e8ee5df
| | Author: imshota <imshotaseo@icloud.com>
| | Date:   Fri Nov 6 00:41:19 2020 +0900
| | 
| |     merge rep
| | 
| * commit e8ee5df83ee5cd44f736ccebd793615f5f876ce8 (refs/remotes/origin/master)
| | Author: imshota <imshotaseo@icloud.com>
| | Date:   Fri Nov 6 00:39:30 2020 +0900
| | 
| |     add repside
| | 
* | commit fc6e6d4619885253500897ccdbf92a82fbd6c07e
|/  Author: imshota <imshotaseo@icloud.com>
|   Date:   Fri Nov 6 00:37:57 2020 +0900
|   
|       add cloneside
| 

リモートリポジトリでenファイルを追加

% cd ../../Git/myproj
% echo enen >> en
% git add en
% git commit -m "add en"
[master d08158d] add en
 1 file changed, 1 insertion(+)
 create mode 100644 en

クローンリポジトリでリベース

% git pull origin main --rebase        
From /Users/shota/Documents/tsclass/プログラム応用開発/Github_pull_request/../Git/myproj
 * branch            main       -> FETCH_HEAD
First, rewinding head to replay your work on top of it...
Applying: change file
Applying: change file cloned
Applying: add foo
Applying: add joy
Applying: add repside
Applying: add en
Applying: add cloneside
% git log --graph --all --decorate=full
* commit 527c710a4f394758f13b8a903ed553d4b058ffcb (HEAD -> refs/heads/master)
| Author: imshota <imshotaseo@icloud.com>
| Date:   Fri Nov 6 00:37:57 2020 +0900
| 
|     add cloneside
| 
* commit 8f2a1c3c4142221f7a892adad5cf2c61213603fc
| Author: imshota <imshotaseo@icloud.com>
| Date:   Fri Nov 6 00:44:06 2020 +0900
| 
|     add en

両方のリポジトリを変更

それぞれのリポジトリでファイルを追加

% echo cloclo >> clone2
% git add clone2
% git commit -m "add clone2"
[master b0891e7] add clone2
 1 file changed, 1 insertion(+)
 create mode 100644 clone2
% cd ../../Git/myproj
% git add rep2
% git commit -m "add rep2"
[master 0f1c791] add rep2
 1 file changed, 1 insertion(+)
 create mode 100644 rep2

クローンリポジトリでリベース

% cd ../../Github_pull_request/cloned 
% git pull origin master --rebase

ログを見てみる

% git log --graph --all --decorate=full
* commit f5ea77b9c3fbbb954ca647cc4ffb337f12605bf3 (HEAD -> refs/heads/master)
| Author: imshota <imshotaseo@icloud.com>
| Date:   Fri Nov 6 00:53:47 2020 +0900
| 
|     add clone2
| 
* commit 0bc414344d540983caf9cc568c6850c528dc0e04
| Author: imshota <imshotaseo@icloud.com>
| Date:   Fri Nov 6 00:37:57 2020 +0900
| 
|     add cloneside
| 
* commit 0f1c791fe4bd1af301f3885e8b60e0dbbb4e4d5d (refs/remotes/origin/master)
| Author: imshota <imshotaseo@icloud.com>
| Date:   Fri Nov 6 00:55:06 2020 +0900
| 
|     add rep2

このように一直線になった。

よって、変わるのは両方のリポジトリが変わった時に、 logが分かれたものを統合するか、一直線になるかになると思われる。

imshota commented 3 years ago

演習4 作業記録

リポジトリclass_proをGithub上で作成
https://github.com/imshota/class_pro

myprojのoriginを設定

% git remote add origin https://github.com/imshota/class_pro.git

ブランチ名をmainに変更

% git branch -M main

プッシュ+上流ブランチとしてmainを設定

% git push -u origin main