Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git checkout modified file without copy-pasting full file path

git status shows something like

git status
# On branch icc-server-send-metric-values
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   java/com/me/cards/preview/preview-card.js

I want to checkout the file, but without retyping it or copy pasting it. The closest command is add -i but this only really cares about the index, not checking out. What's a good workflow here?

like image 229
djechlin Avatar asked Dec 05 '25 14:12

djechlin


1 Answers

Use tab-completion, which virtually every shell provides. There are lots of articles which will help you set this up, including this one for Bash.

As for pure Git solutions:

If that is the only modification, use git checkout . to discard all changes.

If you want to keep some changes and discard others, use git checkout -p to interactively discard changes in the working directory.

When Git prompts you with changes from each file you want to discard, use a:

a - discard this hunk and all later hunks in the file

When Git prompts you with the changes from each file you want to keep, use d:

d - do not discard this hunk or any of the later hunks in the file

like image 184
meagar Avatar answered Dec 07 '25 08:12

meagar