技术标签: Git
在使用Git管理自己的代码版本时,由于编译生成的中间文件,Git使用SHA-1算法来对文件进行加密,进而得出来一个40位的十六进制加密字符串。
325525d8b1f67b5ddd37956a8a728fd26c4ba5ce
但这种算法对于文本文件有效,对于二进制之类的文件则无法正常的进行加密。因此Git版本管理多管理文本文件,而非二进制之类的文件,例如obj文件、.class文件,,并且一些敏感文件和临时文件、日志文件是不能上传到Git远程仓库中的。在Git中提供了.gitignore文件,可以制定自己忽略文件。比如说使用IDEA集成开发环境编写一个项目,在项目根路径下,文件结构如下:
在上图中,由IDEA开发的项目的目录结构如上图所示,其中target目录存放的是项目编译产生的文件,而.idea目录则是特定于IDEA集成开发环境的文件。demo.iml文件也不需要上传到Git。
由于作者在撰写本文时使用IDEA开发,因此以忽略某些IDEA开发环境的特定文件做例子演示
首先打开Git Bash,并且切换到demo根目录,执行git init让git管理该目录。
$ ls -la
total 48
drwxr-xr-x 1 全恒 197609 0 9月 27 09:44 ./
drwxr-xr-x 1 全恒 197609 0 9月 27 09:45 ../
drwxr-xr-x 1 全恒 197609 0 9月 27 09:38 .idea/
drwxr-xr-x 1 全恒 197609 0 8月 29 23:52 .mvn/
-rw-r--r-- 1 全恒 197609 8205 9月 18 17:08 demo.iml
-rwxr-xr-x 1 全恒 197609 6468 8月 22 09:03 mvnw*
-rw-r--r-- 1 全恒 197609 4994 8月 22 09:03 mvnw.cmd
-rw-r--r-- 1 全恒 197609 2707 9月 18 17:06 pom.xml
drwxr-xr-x 1 全恒 197609 0 8月 29 23:52 src/
drwxr-xr-x 1 全恒 197609 0 8月 29 23:52 target/
-rw-r--r-- 1 全恒 197609 5162 8月 28 21:11 zioer5.iml
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo
$ git init
Initialized empty Git repository in D:/Git/demo/demo/.git/
添加远端仓库,在GitHub上建立repository,demo。拷贝远程仓库目录:
[email protected]:yanchenmochen/demo.git
在demo目录执行命令如下:
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git remote add origin [email protected]:yanchenmochen/demo.git
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git remote -v
origin [email protected]:yanchenmochen/demo.git (fetch)
origin [email protected]:yanchenmochen/demo.git (push)
然后执行git add .,和执行git commit –m “first commit”,表示该项目的所有文件均被git管理。
在当前目录生成文件.gitignore,并在其中添加要忽略的文件或目录,每行表示一个忽略规则。
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ vim .gitignore
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ cat .git
.git/ .gitignore
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ cat .gitignore
target/
*.iml
.idea/
在上述的代码片段中新建了配置文件.gitignore,然后忽略了target目录,.idea目录,以后缀.iml结尾的文件。
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git add .gitignore
warning: LF will be replaced by CRLF in .gitignore.
The file will have its original line endings in your working directory.
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git commit -m "[ADD]添加.gitignore配置文件"
[master 202e7b0] [ADD]添加.gitignore配置文件
1 file changed, 3 insertions(+)
create mode 100644 .gitignore
上述的代码片段让Git管理了文件.gitignore,并且执行了一次提交,提交到本地仓库。
使用命令git config配置忽略配置文件.gitignore。
git config core. excludesfile .gitignore
与配置用户名和邮箱是一样的。
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = [email protected]:yanchenmochen/demo.git
fetch = +refs/heads/*:refs/remotes/origin/*
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git config core.excludesfile .gitignore
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ cat .git/config
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
excludesfile = .gitignore
[remote "origin"]
url = [email protected]:yanchenmochen/demo.git
fetch = +refs/heads/*:refs/remotes/origin/*
全恒@Lenovo-PC MINGW64 /d/Git/demo/demo (master)
$ git push origin master
Enumerating objects: 155, done.
Counting objects: 100% (155/155), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (138/138), done.
Writing objects: 100% (155/155), 83.41 KiB | 749.00 KiB/s, done.
Total 155 (delta 69), reused 0 (delta 0)
remote: Resolving deltas: 100% (69/69), done.
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/yanchenmochen/demo/pull/new/master
remote:
To github.com:yanchenmochen/demo.git
* [new branch] master -> master
在这里我们发现,.idea目录,target目录,demo.iml文件等我们想要忽略的文件。
.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。这是因为在之前,自己直接使用git add .把所有的文件,包括target目录,.idea目录,然后执行了
git config core.excludesfile ***
.gitignore只能忽略原来没有被跟踪的文件,因此跟踪过的文件是无法被忽略的。因此在网页上可以看到target等目录的存在。
解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
git rm -r --cached .
git add .
git commit -m ‘update .gitignore’
$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 232 bytes | 232.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To github.com:yanchenmochen/demo.git
202e7b0..9f4fc9c master -> master
登陆网页,查看本次提交:
如果一直使用某个开发工具进行开发项目,则相对于特定项目的忽略文件,所有的项目均要忽略的文件,则可以使用配置全局忽略文件。
使用命令
git config --global core.excludesfile ~/.gitignore
该配置信息位于~/.gitignore。
整体的操作步骤与上述特定于项目的.gitignore是一致的,不再赘述。
这种方式只是临时指定该项目的行为,需要编辑当前项目下的 .git/info/exclude 文件,然后将需要忽略提交的文件写入其中。
需要注意的是,这种方式指定的忽略文件的根目录是项目根目录。
在 .gitignore 文件中,每一行的忽略规则的语法如下:
https://www.cnblogs.com/youyoui/p/8337147.html
https://download.csdn.net/download/lk142500/10692479
Git在程序员开发过程中,不可或缺,因此熟练掌握Git的方方面面,对于提升自己的个人素养和开发效率,不可或缺。
文章浏览阅读789次。给c种不同颜色宝石能穿成多少种长度为s的宝石项链(本质不同)Burnside定理的应用:当n为奇数时,有n种翻转,每种翻转都是以一个顶点和该顶点对边的中点对称。有k^(n/2+1)*n种。当n为偶数时,有n种翻转,其中一半是以两个对应顶点,另一半是以两条对边对称。有k^(n/2+1)*n/2+k^(n/2)*n/2种。..._组合数学项链问题
文章浏览阅读575次,点赞2次,收藏7次。第一题标题:迷宫X星球的一处迷宫游乐场建在某个小山坡上。它是由10x10相互连通的小房间组成的。房间的地板上写着一个很大的字母。我们假设玩家是面朝上坡的方向站立,则:L表示走到左边的房间,R表示走到右边的房间,U表示走到上坡方向的房间,D表示走到下坡方向的房间。X星球的居民有点懒,不愿意费力思考。他们更喜欢玩运气类的游戏。这个游戏也是如此!开始的时候,直升机把10..._第八届蓝桥杯c语言a组
文章浏览阅读1.3k次。建议先了解不同协议和网络层的数据包结构。不然,你将无法了解如何做包分组工作,以及这些工具如何使用。出于学习目的,在使用这些工具列表之前,你必须了解不同协议的数据包,包中的不同字段,这些包字段的含义或目的,以及这些包在网络通信中的使用方式。一旦你知道这些事情,你将能够改变这些值,以便你在网络中看到你所需的效果。1. HpingHping是最受欢迎和免费的抓包工具之一。它允许你修改和发送自定义..._tcap包
文章浏览阅读1.5w次。本文介绍了一种面对linux指令“没有那个文件或目录”时的自查和解决方法_没有那个文件或目录
文章浏览阅读462次。{"rules" : { // 定义对象的set存取器属性时,强制定义get "accessor-pairs": 2, // 指定数组的元素之间要以空格隔开(,后面), never参数:[ 之前和 ] 之后不能带空格,always参数:[ 之前和 ] 之后必须带空格 "array-bracket-spacing": [2, "never"], // 在块级作用域外访问块内定义的变量是否报错提示 "block-scoped-var": 0, // if while functi._eslint 参数
文章浏览阅读3.7k次。问题描述:使用anaconda来管理包,十分方便,也可以到达使得python2和python3共存的目的,但当导入anaconda以外的包时,可能会产生一些问题,在近期学习中,由于会用到scikit-learn模块,此模块为python2.7版本的模块,在使用终端通过pip安装时,ppip默认为为python3安装包。对此,可以尝试用pycharm导入此模块:打开pycharm,选择file菜_mac anaconda 配置两个 python
文章浏览阅读1.1k次。背景在 C++11 之前,无论是类模板还是函数模板,都只能按其指定的样子,接受一组固定数量的模板参数;而C++11 加入了新的表示方法,允许任意个数、任意类别的模板参数,同时也不需要在定义时将参数的个数固定。可变参数模板和普通模板的语义是一样的,只是写法上稍有区别,声明可变参数模板时需要在typename或class后面带上省略号“...”template<typename....._template
文章浏览阅读269次。HTML<a href="" target="_blank"> 业务需求分析书-系统营业日扎帐报表、收费汇总表及收费明细表 </a>cssa{overflow: hidden;text-overflow: ellipsis;white-space: nowrap;width: 100%;display: inline-block;}overflow:..._css a标签超出宽度自动隐藏
文章浏览阅读2k次。References:纠删码解析_向前纠错的编码过程
文章浏览阅读6.8k次,点赞12次,收藏53次。文章目录准备数据搭建模型训练模型推断完整代码在本笔记本中我们将使用在本论文中介绍的Transformer模型。具体来说,我们将使用来自这篇论文中的BERT(Bidirectional Encoder Representations from Transformers)模型。Transformer模型比之前笔记中介绍的任何模型都要大得多。因此,我们将使用transformers library获得预先训练的transformers,并使用它们作为我们的嵌入层。我们将冻结(而不是训练)transformer_基于transformer的情感分析
文章浏览阅读1.2k次。Computational Optimal Transport笔记——Introduction最优运输可以看做是更一般的最短路问题最短路原则:当在给定的点处有一个商品、人或者一些信息,这些东西需要被送到目标点。我们希望使用最少的工作量完成任务。(我们可以沿着直线或者测地线移动)最忧运输理论将这个问题一般化,一个人不是一次移动一个物品而是同时移动多个物品。经证明,有计划地运输一堆个体到指定的位..._最优运输理论 偏微分方程
文章浏览阅读3.4k次。刚入门spring security,感觉东西有点多,不好好研究出了问题都不知道为什么。rememberMe功能配置核心代码(有问题的): protected void configure(HttpSecurity http) throws Exception { List<SysPermission> allPermission = permissionFe..._spring security记住我功能有令牌不实现