Adding Only Untracked Files

前端 未结 11 1916
傲寒
傲寒 2020-12-07 07:04

One of the commands I find incredibly useful in Git is git add -u to throw everything but untracked files into the index. Is there an inverse of that? In the la

11条回答
  •  萌比男神i
    2020-12-07 07:58

    Lot of good tips here, but inside Powershell I could not get it to work.

    I am a .NET developer and we mainly still use Windows OS as we haven't made use of .Net core and cross platform so much, so my everyday use with Git is in a Windows environment, where the shell used is more often Powershell and not Git bash.

    The following procedure can be followed to create an aliased function for adding untracked files in a Git repository.

    Inside your $profile file of Powershell (in case it is missing - you can run: New-Item $Profile)

    notepad $Profile

    Now add this Powershell method:

    function AddUntracked-Git() {
     &git ls-files -o --exclude-standard | select | foreach { git add $_ }
    }
    

    Save the $profile file and reload it into Powershell. Then reload your $profile file with: . $profile

    This is similar to the source command in *nix environments IMHO.

    So next time you, if you are developer using Powershell in Windows against Git repo and want to just include untracked files you can run:

    AddUntracked-Git

    This follows the Powershell convention where you have verb-nouns.

提交回复
热议问题