gitに新しい2つのコマンド
— そな太 (@sonatard) August 16, 2019
git checkoutでできることが多いため機能を分離
ブランチ切り替え
git switch(git checkout)
ブランチ作成と切り替え
git switch -c (git checkout -b)
ファイルのリストア
git restore --source master main.c(git checkout master -- main.c)https://t.co/BeqzXgTbfk
バージョン2.23より前のgitでは下記の両方でcheckout
サブコマンドを利用していた
- ブランチ切り替え操作
- ファイルをコミットされていた状態に戻す操作
2.23からはそれぞれに専用のサブコマンドが割り当てられ、わかりやすくなった。
もうmacではbrew upgradeで更新でき、補完機能にも更新が反映されている。
ブランチ切り替え (git switch
)
$ git switch develop Switched to branch 'develop' Your branch is up to date with 'origin/develop'. $ git switch feature/my-cool-feature Switched to branch 'feature/my-cool-feature' Your branch is up to date with 'origin/feature/my-cool-feature'.
コミットされた状態に戻す (git restore
)
- 変更前の状態
$ git status On branch master nothing to commit, working tree clean $ cat README.md # title
- README.mdの修正
$ echo '`git restore` has come!'>>README.md $ cat README.md # title `git restore` has come! $ git diff diff --git a/README.md b/README.md index 1cbadfb..d72fea0 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ # title +`git restore` has come! $ git status On branch master 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: README.md no changes added to commit (use "git add" and/or "git commit -a")
git restore
で戻す
$ git restore README.md $ git status On branch master nothing to commit, working tree clean $ cat README.md # title
参考
他にもこまごまと更新されている模様
ついでに、Gitの用語をイラストで解説してる画像を見つけたので共有しておきます
去年Gitまわりを触った時に用語多いし意味がわけワカメで、うへぇ🤢てなったけど、いやぁでもこういう類はアウトプットを見据えたインプットが定着が早いし手が動くよなぁと思って「これだけはおさえよう」みたいなのを誰でもわかるように意識して書いて覚えたやつが出てきた…なつい🍉 pic.twitter.com/XHxagBso8S
— ちづみ (@098ra0209) 2019年8月17日