push specific file types
这个问题很常见,因为一个目录下很多文件不是代码,尤其是做Programming Contest,输入输出之类的,因此需要上传指定文件。
git add *.cpp
这个是比较简单的做法,采用wildcard matching, 做了lc之后,就对正则有了新的认识。但是这个有几个缺点
- 可能不能递归到子目录
- 对于每个文件类型都要敲命令,例如有.h, .cpp等
最好的做法是 http://stackoverflow.com/questions/1139762/ignore-files-that-have-already-been-committed-to-a-git-repository
配置.gitignore文件,
*
!*/
!*.c
!*.h
!*.cpp
!*.java
其中!*表示子文件夹一样处理
这样可以解决上面两个问题
对于已经存在的repository,可以先删除,然后再重新push, 用以下命令组合
如果没有.gitignore文件,先touch .gitignore
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
git push -u origin master
…or create a new repository on the command line
echo # MasterThesis >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin git@github.com:zhangruichang/MasterThesis.git
git push -u origin master
…or push an existing repository from the command line
git remote add origin git@github.com:zhangruichang/MasterThesis.git
git push -u origin master
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.