Is it possible to ask git diff
to include untracked files in its diff output, or is my best bet to use git add
on the newly created files and the e
git add -A
git diff HEAD
Generate patch if required, and then:
git reset HEAD
usually when i work with remote location teams it is important for me that i have prior knowledge what change done by other teams in same file, before i follow git stages untrack-->staged-->commit for that i wrote an bash script which help me to avoid unnecessary resolve merge conflict with remote team or make new local branch and compare and merge on main branch
#set -x
branchname=`git branch | grep -F '*' | awk '{print $2}'`
echo $branchname
git fetch origin ${branchname}
for file in `git status | grep "modified" | awk "{print $2}" `
do
echo "PLEASE CHECK OUT GIT DIFF FOR "$file
git difftool FETCH_HEAD $file ;
done
in above script i fetch remote main branch (not necessary its master branch)to FETCH_HEAD them make a list of my modified file only and compare modified files to git difftool
here many difftool supported by git, i configure 'Meld Diff Viewer' for good GUI comparison .
this works for me:
git add my_file.txt
git diff --cached my_file.txt
git reset my_file.txt
Last step is optional, it will leave the file in the previous state (untracked)
useful if you are creating a patch too:
git diff --cached my_file.txt > my_file-patch.patch
Changes work when staged and non-staged with this command. New files work when staged:
$ git diff HEAD
If they are not staged, you will only see file differences.