根据文件名来放置文件,而不管目录 - Git [英] Stage file by its file name, regardless of directory--Git
问题描述
在一个项目中我有非常嵌套的目录,而我是一个懒惰的程序员。
假设我有一个文件名 EventEditor.foo
无论是在根目录或 ./ src / holy / sweet / mother / of / baby / raptor / jesus / this / is / a / long / hiearchy / EventEditor.foo
我的目标是成为Yo Git,添加EventEditor和bam。它只需输入类似于 git add * EventEdi *
的类别即可。这可能吗?或者我每天都在做梦?
如果您希望在使用 git add
,启动您将目录名(例如。
)传递给 git add
作为当前目录的glob,并使确保glob是在引号中,以便Git可以解释它而不是shell:
git add./*EventEdi*\"
一个完整的例子:
$ git init git -add
/Users/lambda/tmp/stackoverflow/git-add/.git/
$ cd git-add /
$ mkdir -p foo / bar / baz中初始化的空Git存储库
$ touch foo / bar / baz / some-long-filename.txt
$ git add./*long-filename*
$ git status
#在分支主机上
#
#初始提交
#
#要提交的更改:
#(使用git rm --cached ...取消存储)
#
#新文件:f oo / bar / baz / some-long-filename.txt
#
从 manual :
Fileglobs(例如可以给出
*。c
)来添加所有匹配的文件。还有一个主要的目录名称(例如dir
来添加dir / file1
和dir / file2
)可以递归地添加目录中的所有文件。
I have very nested directories in a project, and I'm a lazy programmer.
Let's say I have a file name EventEditor.foo
I want to stage my file regardless of whether it's in the root directory or ./src/holy/sweet/mother/of/baby/raptor/jesus/this/is/a/long/hiearchy/EventEditor.foo
My goal would be to be all, "Yo Git, add EventEditor" and bam. It stages it with me only having to type something like git add *EventEdi*
. Is this possible? Or am I day dreaming?
If you would like to match a glob recursively when using git add
, start the glob you pass in to git add
with a directory name (such as .
for the current directory), and make sure that the glob is in quotes so that Git can interpret it instead of the shell:
git add "./*EventEdi*"
A full example:
$ git init git-add Initialized empty Git repository in /Users/lambda/tmp/stackoverflow/git-add/.git/ $ cd git-add/ $ mkdir -p foo/bar/baz $ touch foo/bar/baz/some-long-filename.txt $ git add "./*long-filename*" $ git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached ..." to unstage) # # new file: foo/bar/baz/some-long-filename.txt #
From the manual:
Fileglobs (e.g.
*.c
) can be given to add all matching files. Also a leading directory name (e.g.dir
to adddir/file1
anddir/file2
) can be given to add all files in the directory, recursively.
这篇关于根据文件名来放置文件,而不管目录 - Git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!