git: stage only new files

后端 未结 8 2136
走了就别回头了
走了就别回头了 2020-12-10 05:21

When I have:

  • dirty working directory,
  • dirty staging area,
  • and I copied some new files to the project,

how do I stage only the

相关标签:
8条回答
  • 2020-12-10 05:56

    This alias will respect your ignore patterns (builtin, global and per-directory, as described by the help for git-ls-files --exclude-standard). It will run at the top level of your tree.

    [alias]
    adduntracked=!git add $(git ls-files -o --exclude-standard)
    
    0 讨论(0)
  • 2020-12-10 05:59

    git ls-files -o --exclude-standard | xargs git add

    0 讨论(0)
  • 2020-12-10 06:04

    I suggest something like this to copy:

    for i in source/path ; do cp source/path/$i ./$i ; git add $i ; done
    

    I'm not very well at shell scripting, but this would be an attempt

    0 讨论(0)
  • 2020-12-10 06:04

    git add -u is what I use to stage untracked.

    Edit: comments below have reminded me that its git add . that adds untracked (along with changed files, which I think is not what you want?). I use the git add -u to stage deleted files.

    0 讨论(0)
  • 2020-12-10 06:06

    If you want to add all untracked files to the staging area:

    git add .
    

    I suppose that you want this, while keeping the unstaged changes to tracked files outside of the index.

    git stash
    git add . 
    git stash apply
    

    Would this help?

    0 讨论(0)
  • 2020-12-10 06:06

    A little improvement to the solution of bstpierre, you can use this variation to be able to specify the directory in which you want to add files:

    [alias]
      adduntracked="!f() { git add $(git ls-files -o --exclude-standard $@); }; f"
    
    0 讨论(0)
提交回复
热议问题