計算機科学のブログ

ほしい物リスト

Git - Branching Out: Multiple Trains of Thought - conflict, edit, add, commit, merge

Head First Git: A Learner’s Guide to Understanding Git from the Inside OutRaju Gandhi(著)、 O’Reilly Mediaの Chapter 2.(Branching Out: Multiple Trains of Thought)、SHARPEN YOUR PENCIL(117/164)の解答を求めてみる。

入出力結果(Terminal, Zsh)

% mkdir loving-git
% cd loving-git 
% git init     
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: 	git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: 	git branch -m <name>
Initialized empty Git repository in /Users/.../loving-git/.git/
% code tribute.md
% git add tribute.md 
% git commit    
[master (root-commit) 42b6af8] A
 1 file changed, 1 insertion(+)
 create mode 100644 tribute.md
% git branch improvisation
% git branch 
  improvisation
* master
% git switch improvisation 
Switched to branch 'improvisation'
% code tribute.md
% git add tribute.md 
% git commit -m 'B'
[improvisation 89885ce] B
 1 file changed, 6 insertions(+), 1 deletion(-)
% git switch master 
Switched to branch 'master'
% code tribute.md 
% git add tribute.md 
% git commit -m 'C'
[master 5d4d89f] C
 1 file changed, 6 insertions(+), 1 deletion(-)
% git branch 
  improvisation
* master
% git merge improvisation 
Auto-merging tribute.md
CONFLICT (content): Merge conflict in tribute.md
Automatic merge failed; fix conflicts and then commit the result.
% code tribute.md 
% code .
% code -n tribute.md 
% git switch improvisation 
fatal: cannot switch branch while merging
Consider "git merge --quit" or "git worktree add".
% code tribute.md 
% git switch master 
fatal: cannot switch branch while merging
Consider "git merge --quit" or "git worktree add".
% git branch 
  improvisation
* master
% code -n tribute.md 
% git status         
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   tribute.md

no changes added to commit (use "git add" and/or "git commit -a")
% git merge improvisation 
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.
% git commit -m 'D'  
U	tribute.md
error: Committing 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.
% git add tribute.md 
% git commit -m 'D'
[master b8ffc2c] D
% code .
%

commit graph

B
B
A
A
C
C
D
D
master branch
master branch
improvisation branch
improvisation branch
Text is not SVG - cannot display