Can I use git diff on untracked files?

前端 未结 10 878
你的背包
你的背包 2020-11-27 09:58

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

相关标签:
10条回答
  • 2020-11-27 10:40
    git add -A
    git diff HEAD
    

    Generate patch if required, and then:

    git reset HEAD
    
    0 讨论(0)
  • 2020-11-27 10:42

    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 .

    0 讨论(0)
  • 2020-11-27 10:43

    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
    
    0 讨论(0)
  • 2020-11-27 10:47

    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.

    0 讨论(0)
提交回复
热议问题