have been playing svn,git in recent years has been a gray popular, a little try to play under:
[root@git ~]# git config--global user.name ' Byrd ' #全局设置用户
[root@git ~]# git config--global user.email ' root#t4x.org ' #全局设置用户邮箱
[root@git ~]# git config--global color.ui true #设置颜色
[root@git ~]# git config--list #列出已设置项
User.name=byrd
user.email=root@t4x.org
Color.ui=true
[Root@git ~]# Mkdir/git #建立一个空目录
[Root@git ~]# cd/git/
[Root@git git]# git init #创建一个空仓库
Initialized empty Git repository in/git/.git/
[Root@git git]# Cat Readme.txt
1:hello,world
[Root@git git]# git status #查看当前master分支情况, because a new folder is created, all will prompt
# on Branch Master
#
# Initial Commit
#
# untracked Files:
# (use "Git add <file> ..." to include in what'll be committed)
#
# readme.txt
Nothing added to commit but untracked files present (use "Git add" to track)
[Root@git git]# git add readme.txt #将文件放入暂存区
[Root@git git]# git commit-m "Hello,world" #将文件提交
[Master (Root-commit) 41c7830] Hello,world
1 files changed, 1 insertions (+), 0 deletions (-)
Create mode 100644 readme.txt
[Root@git git]# git status
# on Branch Master
Nothing to commit (working directory clean)
[Root@git git]# git diff readme.txt #比较当前修改和仓库文件对比
Diff--git A/readme.txt B/readme.txt
Index BCFE5E3. D3fded2 100644
---a/readme.txt
+++ B/readme.txt
@@-1 +1,2 @@
1:hello,world
+2:2th
[Root@git git]# git add Readme.txt #可以使用git Add. Represents all files in the current directory
[Root@git git]# git commit readme.txt-m "2th" #可以改成git commit-m "2th"
[Master 2b91b7b] 2th
1 files changed, 1 insertions (+), 0 deletions (-)
[Root@git git]# git log
Commit 2B91B7BF0ACAEF5603DC4B2E49371C3FEDF93D0E
Author:byrd <root@t4x.org>
Date:tue Aug 30 06:14:06 2016 +0800
2th
Commit 41c78306340288daee42ea98727efac8941b624f
Author:byrd <root@t4x.org>
Date:tue Aug 30 06:07:19 2016 +0800
Hello,world
[Root@git git]# Cat Readme.txt
1:hello,world
2:2th
[Root@git git]# git reset--hard head^ #回退一个版本git Reset--hard head^^ Several ^ representations several versions
Head are now at 41c7830 Hello,world
[Root@git git]# Cat Readme.txt
1:hello,world
[Root@git git]# git reflog #可以查看所有分支的所有操作记录
41c7830 head@{0}: head^: Updating head
6471806 Head@{1}: commit:2th
41c7830 head@{2}: head^: Updating head
2b91b7b head@{3}: commit:2th
[Root@git git]# git reset--hard 2b91b7b #回退到某个固定修改
Head are now at 2b91b7b 2th
[Root@git git]# Cat Readme.txt
1:hello,world
2:2th
[Root@git git]# git commit-m "3th" readme.txt
[Master afe6480] 3th
1 files changed, 1 insertions (+), 0 deletions (-)
[Root@git git]# Cat Readme.txt
1:hello,world
2:2th
3:3th
4:4th
[Root@git git]# git checkout readme.txt #git checkout--readme.txt UNCOMMITTED can checkout
[Root@git git]# Cat Readme.txt
1:hello,world
2:2th
3:3th
Advanced Chapter:
[Root@git git]# ssh-keygen-t rsa-c "pub#t4x.org" #设置key, you can submit the key to the GitHub, the local submission to the GitHub
[Root@git git]# Cat/root/.ssh/id_rsa.pub
[Root@git git]# tail-1/etc/hosts
1.1.1.103 gitlab.ssh.t4x.org
[Root@git git]# git remote add Origin git@gitlab.ssh.t4x.org:byrd/t4x.git #我本地搭建了gitlab, local test
[Root@git git]# cat. Git/config | grep t4x.org
URL = git@gitlab.ssh.t4x.org:byrd/t4x.git
[Pub@git project]$ Git push-u Origin master #本地数据提交到仓库
The authenticity of host ' gitlab.ssh.t4x.org (1.1.1.103) ' can ' t be established.
RSA key fingerprint is 26:e5:f9:83:91:b7:96:ed:48:01:b8:3a:00:f0:16:71.
Are you sure your want to continue connecting (yes/no)? Yes
warning:permanently added ' gitlab.ssh.t4x.org,1.1.1.103 ' (RSA) to the list of known hosts.
Counting objects:3702, done.
Compressing objects:100% (3556/3556), done.
Writing objects:100% (3702/3702), 26.49 MiB | 7.15 mib/s, done.
Total 3702 (Delta 453), reused 0 (Delta 0)
To Git@gitlab.ssh.t4x.org:publicgroup/project-pub.git
* [New branch] Master-> Master
Branch Master set up to track remote Branch master from Origin.
[Pub@git project]$ git push-u Origin Master
To Git@gitlab.ssh.t4x.org:publicgroup/project-pub.git
! [Rejected] Master-> Master (Non-fast-forward)
Error:failed to push some refs to ' git@gitlab.ssh.t4x.org:publicgroup/project-pub.git '
To prevent losing history, Non-fast-forward updates were rejected
Merge the remote changes before pushing again. The ' note about
Fast-forwards ' section of ' git push--help ' for details.
[Pub@git project]$ Git pull Origin master #将数据拉回本地
Remote:counting Objects:3, done.
Remote:compressing objects:100% (3/3), done.
Remote:total 3 (Delta 2), reused 0 (Delta 0)
Unpacking objects:100% (3/3), done.
From Gitlab.ssh.t4x.org:publicgroup/project-pub
* Branch Master-> fetch_head
Updating 7803093..7D907D3
Fast-forward
go.php | 1 +
1 files changed, 1 insertions (+), 0 deletions (-)
[Pub@git project]$ git add go.php
[Pub@git project]$ git commit go.php-m "delete lines"
[Master 51f4544] Delete lines
1 files changed, 0 insertions (+), 1 deletions (-)
[Pub@git project]$ git push-u Origin Master
Counting Objects:5, done.
Compressing objects:100% (3/3), done.
Writing objects:100% (3/3), 292 bytes, done.
Total 3 (Delta 2), reused 0 (Delta 0)
To Git@gitlab.ssh.t4x.org:publicgroup/project-pub.git
7d907d3.. 51f4544 Master-> Master
Branch Master set up to track remote Branch master from Origin.
General mode of operation:
One, Git Global setup Configuration
git config--global user.name "int"
git config--global user.email "int@t4x.org"
Create a new repository build a warehouse
git clone git@gitlab.ssh.t4x.org:int/1111.git
CD 1111
Touch readme.md
git add readme.md
Git commit-m "Add README"
Git push-u Origin Master
Three, Existing folder or Git repository already have a warehouse
CD Existing_folder
Git init
Git remote add Origin git@gitlab.ssh.t4x.org:int/1111.git
git Add.
Git commit
Git push-u Origin Master
[Int@git project-pub]$ git push-u Origin Master
To Git@gitlab.ssh.t4x.org:publicgroup/project-pub.git
! [Rejected] Master-> Master (Non-fast-forward)
Error:failed to push some refs to ' git@gitlab.ssh.t4x.org:publicgroup/project-pub.git '
To prevent losing history, Non-fast-forward updates were rejected
Merge the remote changes before pushing again. The ' note about
Fast-forwards ' section of ' git push--help ' for details.
[Int@git project-pub]$ Git pull Origin Master
Remote:counting Objects:3, done.
Remote:compressing objects:100% (3/3), done.
Remote:total 3 (Delta 2), reused 0 (Delta 0)
Unpacking objects:100% (3/3), done.
From Gitlab.ssh.t4x.org:publicgroup/project-pub
* Branch Master-> fetch_head
Updating D27bb42. F2a4d14
Fast-forward
go.php | 1-
1 files changed, 0 insertions (+), 1 deletions (-)