git创建仓库推送文件
2020-02-07Linux90root722°c
A+ A-1. 创建存储版本仓库目录
[[email protected] ~]# mkdir /home/gitroot
2. 初始化仓库,变成可管理的仓库
[[email protected] gitroot]# git init Initialized empty Git repository in /home/gitroot/.git/ [[email protected] gitroot]# ls /home/gitroot/.git/ branches config description HEAD hooks info objects refs
3. 创建一个文件随意写东西,用于做测试
[[email protected] gitroot]# vim 666.txt dasdas sdasd asdas das da sd
4. 把这个文件关联到仓库(添加以及提交到仓库命令)
[[email protected] gitroot]# git add 666.txt [[email protected] gitroot]# git commit -m "add good 666.txt" [master (root-commit) d52feea] add good 666.txt 1 files changed, 8 insertions(+), 0 deletions(-) create mode 100644 666.txt
注释:-m “add good 666.txt” 只是一个描述,大家可以自定义。 假设666.txt文件里面我们做了修改,但是没有提交上去,我们发现改错了。现在怎么恢复呢?
[[email protected] gitroot]# vim 666.txt (随意增加内容)
用git status检查是否有版本差异(提示我们已经做了一些修改,但是没有提交)
[[email protected] gitroot]# git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: 666.txt # no changes added to commit (use "git add" and/or "git commit -a")
恢复到仓库里面的版本,假如改错了.(恢复命令,没有提示说明恢复正确)
[[email protected] gitroot]# git checkout -- 666.txt
查看是否恢复
[[email protected] gitroot]# cat 666.txt dasdas sdasd asdas das da sd as d
检查是否有更改
[[email protected] gitroot]# git status # On branch master nothing to commit (working directory clean)
再做一个测试,还是在666.txt添加内容
[[email protected] gitroot]# vim 666.txt
新增加的和仓库的版本进行比较
[[email protected] gitroot]# git diff diff --git a/666.txt b/666.txt index 3aee3e0..bd10334 100644 --- a/666.txt +++ b/666.txt @@ -1,8 +1,8 @@ -dasdas -sdasd -asdas -das -da -sd -as +d55555asdas +sdasd5 +asdas55 +das5 +da5 +sd5 +as5 d
如没有问题,现在开始提交(一定要写描述哈)
[[email protected] gitroot]# git add 666.txt [[email protected] gitroot]# git commit -m "add a line nue" [master 35c58c5] add a line nue 1 files changed, 7 insertions(+), 7 deletions(-)
现在再次测试,是否有版本差异或进行比较
[[email protected] gitroot]# git status # On branch master nothing to commit (working directory clean) [[email protected] gitroot]# git diff
标签:Git