Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

--dry-run option in git checkout

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.

like image 623
Karthik Bose Avatar asked Jul 03 '12 08:07

Karthik Bose


People also ask

What does dry run do in git?

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.

What is git checkout command?

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.

How do I discard changes in git?

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.


1 Answers

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.

like image 118
vergenzt Avatar answered Oct 02 '22 16:10

vergenzt