A, Git based on the concept
Git features a brief overview
Any time you can roll back to previous versions of the code (
git reset --hard
);It will not cover someone else's code (branch) when co-development;
Leaving revision history (
git log
);You can easily manage different version made version;
1, Git operating mode
operating
90% or more operations on a personal computer
Add files, modify files, submit changes, view version history
Repository synchronization
The locally modified version pushed to the server
Version control system:
2, Git file storage
Note the different file storage and SVN:
Git does not treat or save data in accordance with SVN that. Conversely, Git more like a data snapshot as a set of small file system. Every time you submit updates, or save the state of the project in Git, it was mainly to make a snapshot of all files and saves a snapshot of the index. For efficient, if files have not changed, Git does not re-store the file, but retain only files stored before a link to . Git more like a snapshot of the data to the stream.
Features summary:
Direct recording snapshots
snapshoot
. Rather than differences;Almost all operations are performed locally;
Time maintain data integrity ;
Many operations add data only;
Three states file (only in three states)
Modified (
modified
)Has been staging (
staged
)Submitted (
committed
)
3, Git file status
Git file: management has been the repository of documents;
Modified: the working directory (
working directory
modified Git file);It has been staging: Staging Git perform operations on the modified file, the file is stored in temporary storage area (
staging area
); (SVN does not pay attention to the concept of temporary storage area)已提交: 将已暂存的文件执行Git提交操作,将文件存入版本库(
git directory
);
Git 仓库目录是 Git 用来保存项目的元数据和对象数据库的地方。 这是 Git 中最重要的部分,从其它计算机克隆仓库时,拷贝的就是这里的数据。
工作目录是对项目的某个版本独立提取出来的内容。 这些从 Git 仓库的压缩数据库中提取出来的文件,放在磁盘上供你使用或修改。
暂存区域是一个文件,保存了下次将提交的文件列表信息,一般在 Git 仓库目录中。 有时候也被称作‘索引’,不过一般说法还是叫暂存区域。
基本的 Git 工作流程如下:
在工作目录中修改文件。
暂存文件,将文件的快照放入暂存区域
git add
。提交更新,找到暂存区域的文件,将快照永久性存储到 Git 仓库目录
git commit
。
git add 放到暂存区;
git commit 从暂存区放到版本仓库中;
4、本地版本库与服务器版本库
Git是分布式的。
二、Git常用命令
1、config和email
关于配置user.name
和user.email
:
可以有三个地方配置:
比如输入git config
命令, 会出现下面三个信息,即系统级别system
,全局global
,和局部local
。其中优先级不断升高。
zxzxin@zxzxin:~/Git/gitlearn$ git config usage: git config [<options>] Config file location --global use global config file --system use system config file --local use repository config file -f, --file <file> use given config file --blob <blob-id> read config from given blob object
这里展示一下配置我们局部的gitlearn
仓库:
git 提交的id(commit id
)是一个摘要值,这个摘要值实际上是一个sha1
计算出来的。
2、git rm 和rm的区别
git rm :
1、删除了一个文件
2、将被删除的文件纳入到了暂存区(stage);(可以直接调用
git commit
来提交)
若想恢复被删除的文件,需要进行两个动作:
1、
git reset HEAD test2.txt
,将待删除的文件从暂存区恢复到工作区;2、
git checkout -- test2.txt
, 将工作区的修改丢弃掉;
**rm **:
只是将文件删除;注意: 这时,被删除的文件并未纳入到暂存区当中。
这时是提交(
git commit
)不了的。要想纳入暂存区,必须要再调用一次git add
。
实战对比:
3、git mv 和 mv的对比
git mv(和git rm
类似):
先完成重命名;
然后提交到暂存区;
git mv
演示:
而 mv:
只是完成重命名;
需要自己调用
git add
提交到暂存区;
使用技巧: 可以通过git commit --amend -m '修正内容'
更改上次错误的提交消息。(就是-m ''
)后面的提交信息写错了。
4、git log查看日志
git log -n
可以查看最近的n
条日志。
git log --pretty=oneline
以一行一行的方式显示出来。
查看git命令帮助:
5、.gitignore
文件
在开发中,如果我们不想将所有的文件都放到git当中,而是要忽略少数一些文件(比如jar
包、配置文件等),我们可以在我们的目录创建一个.gitignore
文件,git就不会将这些文件放入暂存区,也不会提交(不会加入版本控制系统)。
此时我们可以创建一个.gitignore
文件:
简而言之,放在.gitignore
中的文件会直接被git
无视。
其中,放在.gitignore
中的文件也支持正则表达式。
例如:
*.a
,会忽略所有.a
结尾的文件;!lib.a
,不要忽略lib.a
(排除这个忽略);/test.txt
,仅仅忽略项目根目录下的TODO
文件,不包括子目录下的test.txt
文件;dir1/
,忽略dir1/
目录下的所有文件;dir1/*.txt
Ignoreddir1/a.txt
but will not be includeddir1/dir2/a.txt
.For example
dir1/*.txt
ignoresdir1
all under the.txt
documents,dir1/*/*.txt
will be ignoreddir1
at all layers under.txt
, anddir1/**/*.txt
ignoresdir1/
any layer in the.txt
document.
In .gitignore
using #
indicates a comment.
Original: the Java architecture notes
Free Java needs its own advanced data collection, covering Java, Redis, MongoDB, MySQL, Zookeeper, Spring Cloud, Dubbo distributed high concurrency and other tutorials, a total of 30G.
Portal: https://mp.weixin.qq.com/s/JzddfH-7yNudmkjT0IRL8Q