計算機科学のブログ

ほしい物リスト

Git - Undoing: Fixing Your Mistakes - subcommands, reset, restore

Head First Git: A Learner’s Guide to Understanding Git from the Inside OutRaju Gandhi(著)、 O’Reilly Mediaの Chapter 4.(Undoing: Fixing Your Mistakes)、EXERCISE(316/680)の解答を求めてみる。

|HEAD3|A| |HEAD^1|E| |HEAD^21|D| |HEAD^2|F| |HEAD^1~2|A|

入出力結果(Terminal, Zsh)

% git branch
* boardgame-night
  glamping-trip
  main
% git status
On branch boardgame-night
nothing to commit, working tree clean
% git log --oneline --all --graph
* 39107a6 (HEAD -> boardgame-night) add games and list potential boardgame night venues
* 3e3e847 initial boardgame planning
| * cf5e718 (glamping-trip) initial outdoors plan
|/  
* 8d704f8 (main) first cut at invitation card
* 6e16680 initial set of guests and gift registry
% git reset --mixed ~HEAD
zsh: no such user or named directory: HEAD
% git reset --mixed HEAD~1
Unstaged changes after reset:
M	indoor-party.md
% git status
On branch boardgame-night
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   indoor-party.md

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	boardgame-venues.md

no changes added to commit (use "git add" and/or "git commit -a")
% git log --oneline --all --graph
* 3e3e847 (HEAD -> boardgame-night) initial boardgame planning
| * cf5e718 (glamping-trip) initial outdoors plan
|/  
* 8d704f8 (main) first cut at invitation card
* 6e16680 initial set of guests and gift registry
% git restore indoor-party.md 
% ls
boardgame-venues.md	guest-list.md		invitation-card.md
gift-registry.md	indoor-party.md
% rm boardgame-venues.md 
% git status 
On branch boardgame-night
nothing to commit, working tree clean
% git log --oneline --all --graph
* 3e3e847 (HEAD -> boardgame-night) initial boardgame planning
| * cf5e718 (glamping-trip) initial outdoors plan
|/  
* 8d704f8 (main) first cut at invitation card
* 6e16680 initial set of guests and gift registry
%