Gitの動作を理解するために、Gitのコマンドを実際に試して、結果を見てみました。
1つの記事内で一連のGitコマンドが完結しているので、これら一連のコマンドを順に実行させて結果を見ることで、一連のGitの動作を実際に体感でき、一通り独習することが可能です。
※前回記事のリポジトリ状態からの続きになっています。
前回記事へ | 目次へ:Git関連記事のまとめページ | 次回記事へ |
---|
実行例
(※試行用にlocal-repo3を作成)
cd /test-space
mkdir local-repo3
cd /test-space/local-repo3
git init
git remote add origin "D:/test-space/remote-repo1.git"
git log
↓
結果:
fatal: your current branch 'master' does not have any commits yet
-----
※チェックアウトせずにリモートリポジトリにブランチを作成
git push origin c69a305:refs/heads/branch-F1
↓
結果:
error: src refspec c69a305 does not match any
error: failed to push some refs to 'D:/test-space/remote-repo1.git'
(※作成位置のコミット履歴がないと、ブランチを作成できない模様)
-----
git fetch origin master branch-R1
git log --oneline --graph --all
↓
結果:
* 1247fa9 (origin/master) message R4
* fab68d8 message R3
* c69a305 message R1
* 94996a0 message4
| * e009b2d (origin/branch-R1) message R2
|/
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1
※チェックアウトせずにリモートリポジトリにブランチを作成
git push origin c69a305:refs/heads/branch-F1
↓
結果:
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To D:/test-space/remote-repo1.git
* [new branch] c69a305 -> branch-F1
git log --oneline --graph --all
↓
結果:
* 1247fa9 (origin/master) message R4
* fab68d8 message R3
* c69a305 (origin/branch-F1) message R1
* 94996a0 message4
| * e009b2d (origin/branch-R1) message R2
|/
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1
※この指定の方法では作成不可
git push origin 94996a0:branch-F2
↓
結果:
error: The destination you provided is not a full refname (i.e.,
starting with "refs/"). We tried to guess what you meant by:
- Looking for a ref that matches 'branch-F2' on the remote side.
- Checking if the <src> being pushed ('94996a0')
is a ref in "refs/{heads,tags}/". If so we add a corresponding
refs/{heads,tags}/ prefix on the remote side.
Neither worked, so we gave up. You must fully qualify the ref.
hint: The <src> part of the refspec is a commit object.
hint: Did you mean to create a new branch by pushing to
hint: '94996a0:refs/heads/branch-F2'?
error: failed to push some refs to 'D:/test-space/remote-repo1.git'
-----
cd /test-space/remote-repo1.git
git log --oneline --graph --all
↓
結果:
* 1247fa9 (HEAD -> master) message R4
* fab68d8 (branch-R2) message R3
* c69a305 (branch-F1) message R1
* 94996a0 message4
| * e009b2d (branch-R1) message R2
|/
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1
(※リモートリポジトリにブランチが作成されている)
cd /test-space/local-repo3
-----
(※元に戻す)
※リモートリポジトリのブランチを削除
git push --delete origin branch-F1
↓
結果:
To D:/test-space/remote-repo1.git
- [deleted] branch-F1
git log --oneline --graph --all
↓
結果:
* 1247fa9 (origin/master) message R4
* fab68d8 message R3
* c69a305 message R1
* 94996a0 message4
| * e009b2d (origin/branch-R1) message R2
|/
* 20bbab7 message3
* 00cad71 message2
* 4ace194 message1
-----
(※local-repo3を削除)
cd /test-space
rd /s /q "/test-space/local-repo3"
環境
Windows 10、PortableGit-2.40.0-64-bitを使用、全てローカルPC上で実施、GitHub等は不使用。