试图做出一些改变.我曾经git add使用通配符添加了我可能创建的任何新的javascript文件*.js.然后我提交了更改并推送到github:
git add *.js git commit -m "stuff" git push github master
当我检查github时,我编辑的所有文件都是空白的.他们在那里,只是空着.
然后我再次尝试提交,但GIT说一切都是最新的.
然后我回过头来注意到,在我做完之后git commit -m "stuff",GIT显示了一条消息,说我的一些".js"文件没有上演,即使我刚刚使用通配符添加它们:git add *.js.这是我尝试提交时显示的消息.
# On branch master # Changes not staged for commit: # (use "git add/rm ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # modified: src/static/directory1/js/module1/file1.js # modified: src/static/directory1/js/module1/file2.js # modified: src/static/directory1/js/module2/file1.js
为了解决这个问题,我必须在执行git add以下操作时查看几个目录:
git add src/static/directory1/*.js
这看起来很有效,因为在我再次提交之后文件就在那里然后推送到github:
git commit -m "stuff" git push github master
这里发生了什么,为什么我必须在几个目录中导航才能使外卡工作?
谢谢!
Aar*_*ray 32
你需要使用
git add '*.js'
Run Code Online (Sandbox Code Playgroud)
你必须使用引号,所以git在你的shell之前收到通配符.如果没有引号,shell将只在当前目录中进行通配符搜索.
Gre*_*ill 12
即使我刚刚使用通配符添加它们:
git add *.js
壳牌通配符扩展并不会递归到子目录.在Git有机会看到它之前,通配符已经扩展.
如果您使用git add '*.js',那么Git将看到通配符并将其与所有以此结尾的路径名匹配.js.因为*它处于初始位置,所以最终将递归地添加.js包括在子目录中的所有文件.
另一种方法是使用find命令:
find . -name '*js' -exec git add {} \;
Run Code Online (Sandbox Code Playgroud)
在没有exec的情况下运行它将为您提供正在处理的文件列表; 所以,很容易根据自己的喜好调整此命令.