How to git checkout a file on another branch using "restore" instead?
Answer a question
I am trying to rebuild my git workflow by using restore instead of the old checkout. I knew that restore can undo my previous work (on my branch). But what if I want to checkout a file from another branch? The checkout version is quite simple,
git checkout main -- my-file
Can I do the same thing with restore command?
My further question is: should I totally move from checkout to switch and restore since they already split some features apart, like:
git checkout -b new-branch ===> git switch -c new-branch
git checkout -- my-file ===> git restore -- my-file
I mean if I can also checkout a file from another branch using restore, there's almost no need of checkout in simple daily use.
Feel free to redirect this question to other similar one if any.
Answers
As far as I know, the intention is to replace git checkout with git restore and git switch as appropriate.
Where git checkout takes two positional arguments to specify the branch and a file within that branch, git restore uses the --source argument to specify the "tree" (could be a branch, tag, commit, etc) from which to take the file given as a positional argument.
# git checkout dev my-file
git restore --source dev my-file
更多推荐


所有评论(0)