git忽略特定文件或目录

来源:互联网 发布:青春期知乎 编辑:程序博客网 时间:2024/05/17 03:42


        开发人员在将某个目录添加到git版本库、或提交某个git版本库的改动时,可能希望忽略掉一些文件或目录(如编译时生成的.o、.a文件等),可以修改.git/info/exclude文件来实现。

举例如下:


vi .git/info/exclude


# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
*.[oa]        #忽略以.o或.a结尾的文件或目录
*.pyc        
*.exe       #忽略以.exe结尾的文件或目录
.*              #忽略以.开头的文件或目录
*.rar
*.zip
*.gz
*.bz2
*.db
*.sqlite

git在提交之前撤销add 操作 

 使用 git rm -r --cached . 


git在提交时忽略某些目录

在目录下创建.gitignore
内容:
log/

假设log目录下有:
log/
--1.log
--2.log

新建一个空文件:.gitkeep,文件名随意,这里只是为了说明。

执行命令:git add log/.gitkeep -f 
这里如果不加-f会出现错误:
$ git add log/.gitkeep
The following paths are ignored by one of your .gitignore files:
log
Use -f if you really want to add them.
fatal: no files added


提交上传。


0 0
原创粉丝点击