View changes before commit in Git

Usually before committing changes in Git developer verify one last time all changes he did. Normally we use git difftool command in order to do it. In that case git will ask you a question if you want to see changes before opening each file. When the number of changed files are big or when different types of files are changed and not all files should be part of commit, it may be helpful to filter what types of file we want to verify and disable message asking about each file.

How to disable message asking if you want to see diff for the file

When providing -y parameter to git difftool command, git will not ask you any questions and will just open default difftool

#do not ask user confirmation before showing diff for file
git difftool -y

How to filter files using wildcards when doing git diff

And when provided filter -- **/*.cs git will open difftool only for files matching wildcards, in this case C# files only.

#notice space after -- it is required
#it matches all folders and subfolders where file extension is *.cs (c#)
git difftool -- **/*.cs
#do not ask for user confirmation for all *.cs files
git difftool -y -- **/*.cs 

how to view changes in git before commit



Comments

Social media

Search

Latest Tweets