yashinomi / sysdev2020_advanced

0 stars 0 forks source link

Class 4.(後半) Exercise 2. log #19

Closed yashinomi closed 3 years ago

yashinomi commented 3 years ago

リモートのコミット、手元のコミット どう違う。

yashinomi commented 3 years ago

とりあえずgit作業の練習をした方のリポジトリを再度clone。 (これはクローン先)

$ cd ..
$ git clone ~/PathToWorkspace/workdir ./cloned_workdir
Cloning into './cloned_workdir'...
done.
$ cd cloned_workdir
yashinomi commented 3 years ago

リモートリポジトリにコミットする。

(これはリモートリポジトリ内)

$ echo "new commit" >> hoge.txt
$ git commit -a

これはGitHubにpushしない。

yashinomi commented 3 years ago

(これはクローン先)

$ cd cloned_workdir
$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 253 bytes | 84.00 KiB/s, done.
From /PathToWorkspace/workdir
   23e42c8..c210e09  master     -> origin/master
Updating 23e42c8..c210e09
Fast-forward
 hoge.txt | 1 +
 1 file changed, 1 insertion(+)

GitHubにpushしていなくても、ちゃんとpullに反映される。

yashinomi commented 3 years ago

(これはクローン先) コミットを作成。

$ echo "new commit from clone" >> hoge.txt 
$ git commit -a 
[master e235151] commit from clone
 1 file changed, 1 insertion(+)
$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 288 bytes | 288.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote: 
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote: 
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To /PathToWorkspace/workdir
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/PathToWorkspace/workdir'

エラーした。

yashinomi commented 3 years ago

クローン元・リモート側の中身をGitHubにPush&Pullしたら解決する???

(これはリモート)

$  git pull 
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 641 bytes | 128.00 KiB/s, done.
From yashi_hub:yashinomi/git_practice
   23e42c8..77600cd  main       -> origin/main
Merge made by the 'recursive' strategy.
 readme.md | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
$ git push origin HEAD:main 

Enumerating objects: 9, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 520 bytes | 520.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 1 local object.
To yashi_hub:yashinomi/git_practice.git
   77600cd..01b37dd  HEAD -> main

同じエラーを吐いた。

yashinomi commented 3 years ago

リモートをBareレポジトリにした方が良い、しない方が良いと様々なことが言われいてる。

yashinomi commented 3 years ago

先生から直し方を言われた。リモートの現在のブランチを別のものにすれば良いらしい。 これはリモート。

$ git checkout br-a
Switched to branch 'br-a'
Your branch is up to date with 'origin/br-a'.

これはクローン先.

$ git push
Enumerating objects: 9, done.
Counting objects: 100% (8/8), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 611 bytes | 611.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0), pack-reused 0
To /PathToWorkspace/workdir
   01b37dd..11c42a4  master -> master