Git - Undoing: Fixing Your Mistakes - reset command, soft flag
Head First Git: A Learner’s Guide to Understanding Git from the Inside Out、 Raju Gandhi(著)、 O’Reilly Mediaの Chapter 4.(Undoing: Fixing Your Mistakes)、SHARPEN YOUR PENCIL(3/715)の解答を求めてみる。
入出力結果(Terminal, Zsh)
% 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>
hint:
hint: Disable this message with "git config set advice.defaultBranchName false"
Initialized empty Git repository in /Users/.../.git/
% touch a.txt
% git add a.txt
% git commit -m 'A'
[master (root-commit) ead1835] A
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 a.txt
% touch b.txt
% git add b.txt
% git commit -m 'B'
[master 5d95935] B
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 b.txt
% ls
a.txt b.txt
% git log --oneline
5d95935 (HEAD -> master) B
ead1835 A
% git reset --soft ead1835
% ls
a.txt b.txt
% git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: b.txt
%