设为首页 收藏本站
查看: 802|回复: 0

[经验分享] linux命令之git

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-4-28 09:42:49 | 显示全部楼层 |阅读模式
git其实是一种多人开发项目时候的版本控制系统,是由LINUX之父Linus开发的,与SVN最大的区别在于可以支持离线操作。
   首先安装:我用的网易的yum源http://mirrors.163.com/centos/6/os/x86_64/
              然后yum install git -y



  • Git初始化



[iyunv@localhost ~]#git --version                                查看git版本
[iyunv@localhost ~]#git config --global user.name dangwanqiang   当前用户姓名和邮箱
[iyunv@localhost ~]#git config --global color.ui true            在git输出中开启颜色显示
[iyunv@localhost ~]#git config --list
1
2
3
user.name=dangwanqiang
user.email=goodang517@163.com
color.ui=true



实际也是写入文件中去

[iyunv@localhost ~]#cat ~/.gitconfig
1
2
3
4
5
[user]
name = dangwanqiang
email = goodang517@163.com
[color]
ui = true




  • 建立一个工作目录


[iyunv@localhost ~]#git init github
[iyunv@localhost ~]#cd github
[iyunv@localhost github]#ls -A                                 
.git                    可以看到隐藏的目录.git(Git版本库,repository)

  • 在工作目录下的建立操作


三部曲:1.init  2.add  3.commit
wKioL1cgnBeiQSvuAABfM3SA6yE684.jpg
[iyunv@localhost github]# touch READ.txt  a.py           //创建自己的工作文件
[iyunv@localhost github]# git status
1
2
3
4
5
6
7
8
9
10
# On branch master
#
# Initial commit
#
# Untracked files:                                           //未添加到版本库的文件
#   (use "git add <file>..." to include in what will be committed)
#
#READ.txt
#a.py
nothing added to commit but untracked files present (use "git add" to track)



[iyunv@localhost github]# git add a.py                    //将a.py加到版本库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
[iyunv@localhost github]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:                              
#   (use "git rm --cached <file>..." to unstage)
#
#new file:   a.py
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#READ.txt



[iyunv@localhost github]# git add READ.txt            //将READ.txt加到版本库
[iyunv@localhost github]# git status
1
2
3
4
5
6
7
8
9
10
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#new file:   READ.txt
#new file:   a.py
#



[iyunv@localhost github]# git commit -m 'init commit'         //-m参数指定提交说明
1
2
3
4
[master (root-commit) 9f045e6] init commit
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 READ.txt
create mode 100644 a.py



[iyunv@localhost github]# git status
1
2
# On branch master
nothing to commit, working directory clean



[iyunv@localhost github]# vi a.py                            //对a.py再次进行修改

[iyunv@localhost github]# git status -s                     
M a.py
            注:工作区与暂缓区不同,即M标志位在第二位,也意味着需要执行add
[iyunv@localhost github]# git status

1
2
3
4
5
6
7
8
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory
#
#modified:   a.py
#
no changes added to commit (use "git add" and/or "git commit -a")



[iyunv@localhost github]# git diff                     //查看工作区与暂缓区具体不同
1
2
3
4
5
6
7
diff --git a/a.py b/a.py
index 72943a1..dbee026 100644
--- a/a.py
+++ b/a.py
@@ -1 +1,2 @@
aaa
+bbb



[iyunv@localhost github]# git add a.py

[iyunv@localhost github]# git status -s                    
M  a.py
           注:暂缓区与最终版本库不同,即M标志位在第一位,也意味着需要执行commit

[iyunv@localhost github]# git status
1
2
3
4
5
6
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#modified:   a.py
#



[iyunv@localhost github]# git diff --staged            //查看暂缓区与最终版本库的具体不同
1
2
3
4
5
6
7
diff --git a/a.py b/a.py
index 72943a1..dbee026 100644
--- a/a.py
+++ b/a.py
@@ -1 +1,2 @@
aaa
+bbb



  • 在工作目录下的撤销误操作


wKioL1cgpmqhwujvAABynmasX5s174.jpg

  • 在工作目录下的删除重命名操作

[iyunv@localhost github]# git rm a.py                //删除缓存区和工作区的文件
1
rm 'a.py'



[iyunv@localhost github]# git status
1
2
3
4
5
6
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#deleted:    a.py
#



[iyunv@localhost github]# git status -s
1
D  a.py



[iyunv@localhost github]# ls
READ.txt

[iyunv@localhost github]# git commit -m 'delete a.py'   //将删除提交到最终版本库
1
2
3
[master 480eda1] delete a.py
1 file changed, 2 deletions(-)
delete mode 100644 a.py



[iyunv@localhost github]# git status
1
2
# On branch master
nothing to commit, working directory clean



[iyunv@localhost github]# git rm --cached READ.txt       //只删除暂存区的文件
1
rm 'READ.txt'



[iyunv@localhost github]# ls
READ.txt
[iyunv@localhost github]# git reset READ.txt             //从最终版本库恢复文件到暂存区
[iyunv@localhost github]# ls
READ.txt
[iyunv@localhost github]# git status
1
# On branch master



[iyunv@localhost github]# git mv READ.txt READ.LL
[iyunv@localhost github]# git commit -m 'rename read.txt'


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-209816-1-1.html 上篇帖子: How to Install Git on Ubuntu 12.04 下篇帖子: 给Ubuntu下的Git添加颜色 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表