I use git checkout --<dir_name(or)file_name>
to discard all my changes in the specific directory or in the file. Whenever I do that, GIT checks-out the directory (or) file from the repository.
Is there a way I can tell GIT?, "do not override the changes, just tell me what would happen."
Similar to git clean -n
(or) git clean --dry-run
.
UPDATE:
Before I execute, git checkout --src/
, I would like to see what are the files would be overridden. I know we can use git status src/
. But, wouldn't it be great to have git checkout -n --src/
? Not much command changes for the user.
The --dry-run option can be used to obtain a summary of what is included by any of the above for the next commit by giving the same set of parameters (options and paths). If you make a commit and then find a mistake immediately after that, you can recover from it with git reset.
The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.
There are two Git commands a developer must use in order to discard all local changes in Git, remove all uncommited changes and revert their Git working tree back to the state it was in when the last commit took place. The commands to discard all local changes in Git are: git reset –hard. git clean -fxd.
You can run
$ git checkout --patch -- <files>
and it will ask for each difference whether you want to "check out" that difference. If you say no for each prompt, then it leaves it untouched.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With