Adding Only Untracked Files

前端 未结 11 1899
傲寒
傲寒 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条回答
  • 2020-12-07 07:55

    To add all untracked files git command is

    git add -A

    Also if you want to get more details about various available options , you can type command

    git add -i

    instead of first command , with this you will get more options including option to add all untracked files as shown below :

    $ git add -i warning: LF will be replaced by CRLF in README.txt. The file will have its original line endings in your working directory. warning: LF will be replaced by CRLF in package.json.

    * Commands * 1: status 2: update 3: revert 4: add untracked 5: patch 6: diff 7: quit 8: help What now> a

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2020-12-07 08:00

    git add . (add all files in this directory)

    git add -all (add all files in all directories)

    git add -N can be helpful for for listing which ones for later....

    0 讨论(0)
  • 2020-12-07 08:01

    git ls-files lists the files in the current directory. If you want to list untracked files from anywhere in the tree, this might work better:

    git ls-files -o --exclude-standard $(git rev-parse --show-toplevel)
    

    To add all untracked files in the tree:

    git ls-files -o --exclude-standard $(git rev-parse --show-toplevel) | xargs git add
    
    0 讨论(0)
  • 2020-12-07 08:05

    git ls-files -o --exclude-standard gives untracked files, so you can do something like below ( or add an alias to it):

    git add $(git ls-files -o --exclude-standard)
    
    0 讨论(0)
提交回复
热议问题