git设置忽略文件

                                              作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一".gitignore"文件说明

配置".gitignore"文件让Git不在管理当前目录下的某些文件。

生产中有如下几类文件可能需要忽略:
	- 程序运行时产生的临时的文件;
	- 程序连接数据库这一类的配置文件;
	- 程序本地开发使用的图片文字;
	- 其他不想被共享的文件;

二.配置忽略指定文件案例

1.创建忽略文件

[root@prometheus-server31 devops]# cat .gitignore
/bin
/target
.classpath
.project
.settings
*.h
!test.h
*.py[c|x]
*.swp
*.exe
[root@prometheus-server31 devops]# 

2.将忽略文件提交打本地仓库

[root@prometheus-server31 devops]# git add .gitignore; git commit -m '配置忽略文件'
[kafka c5002de] 配置忽略文件
 1 file changed, 10 insertions(+)
 create mode 100644 .gitignore
[root@prometheus-server31 devops]# 

3.将提交的本地仓库推到远程仓库

[root@prometheus-server31 devops]# touch {1..5}.exe
[root@prometheus-server31 devops]# 
[root@prometheus-server31 devops]# ll
total 36
drwxr-xr-x 3 root root 4096 Nov 17 23:24 ./
drwxr-xr-x 7 root root 4096 Nov 17 19:43 ../
-rw-r--r-- 1 root root    0 Nov 17 23:24 1.exe
-rw-r--r-- 1 root root    0 Nov 17 23:24 2.exe
-rw-r--r-- 1 root root    0 Nov 17 23:24 3.exe
-rw-r--r-- 1 root root    0 Nov 17 23:24 4.exe
-rw-r--r-- 1 root root    0 Nov 17 23:24 5.exe
-rw-r--r-- 1 root root   26 Nov 17 22:31 flink.txt
drwxr-xr-x 8 root root 4096 Nov 17 23:23 .git/
-rw-r--r-- 1 root root   77 Nov 17 23:23 .gitignore
-rw-r--r-- 1 root root   23 Nov 17 19:59 go.mod
-rw-r--r-- 1 root root   26 Nov 17 22:11 k8s.log
-rw-r--r-- 1 root root   26 Nov 17 22:34 kafka.log
-rw-r--r-- 1 root root   16 Nov 17 22:11 office.txt
[root@prometheus-server31 devops]# 
[root@prometheus-server31 devops]# git add . ;git commit -m 'add *.exe'
On branch kafka
Your branch is ahead of 'origin/kafka' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
[root@prometheus-server31 devops]# 
[root@prometheus-server31 devops]# git branch
  flink
* kafka
  master
[root@prometheus-server31 devops]# 
[root@prometheus-server31 devops]# git push origin kafka
Username for 'https://gitee.com': jasonyin2020
Password for 'https://jasonyin2020@gitee.com': 
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 371 bytes | 371.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag 5146499e
To https://gitee.com/jasonyin2020/yinzhengjie-devops-k8s.git
   932ec59..c5002de  kafka -> kafka
[root@prometheus-server31 devops]# 
posted @ 2021-03-31 09:09  尹正杰  阅读(1018)  评论(0编辑  收藏  举报