Git入门操作(github上传与克隆)

参考

https://git-scm.com/book/zh/v2

yum install git -y

创建一个目录(Git仓库)

mkdir gitdemo

cd gitdemo

[root@foundation11 gitdemo]# git init

[root@foundation11 gitdemo]# echo file1 > file1
[root@foundation11 gitdemo]# git add file1
[root@foundation11 gitdemo]# git status -s
A  file1

 git status -s
 M README
MM Rakefile
A  lib/git.rb
M  lib/simplegit.rb
?? LICENSE.txt

[root@foundation11 gitdemo]# git config --global user.mail "hzp@qq.com"
[root@foundation11 gitdemo]# git config --global user.name hzp

[root@foundation11 gitdemo]# git commit -m "add file1"
# On branch master
nothing to commit, working directory clean
[root@foundation11 gitdemo]# git status -s


因为之前提交过了 所以没有状态

修改状态

[root@foundation11 gitdemo]# git status -s
 M file1
[root@foundation11 gitdemo]# echo file1>> file1
[root@foundation11 gitdemo]# git status -s
 M file1
[root@foundation11 gitdemo]# git add file1
[root@foundation11 gitdemo]# git status -s
M  file1
[root@foundation11 gitdemo]# echo file1>> file1
[root@foundation11 gitdemo]# git status -s
MM file1


两个M说明提交后在缓冲区进行了修改

要再次提交

[root@foundation11 gitdemo]# git add file1
[root@foundation11 gitdemo]# git status -s
M  file1

[root@foundation11 gitdemo]# git commit -m "add file1"
[master aef1b8d] add file1
 Committer: hzp <root@foundation11.ilt.example.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 3 insertions(+)

[root@foundation11 gitdemo]# l.
.  ..  .git

[root@foundation11 gitdemo]# vim .gitignore

.*
[root@foundation11 gitdemo]# git status -s
[root@foundation11 gitdemo]# l.
.  ..  .git  .gitignore

修改文件后还原文件

[root@foundation11 gitdemo]# git status
# 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:   file1
#
no changes added to commit (use "git add" and/or "git commit -a")
[root@foundation11 gitdemo]# git checkout -- file1
[root@foundation11 gitdemo]# cat file1
file1
file1
file1
file1


查看日志

[root@foundation11 gitdemo]# git log
commit aef1b8d45c5d8d3692b6c4866480b17101c0ff4b
Author: hzp <root@foundation11.ilt.example.com>
Date:   Sun Mar 31 10:48:01 2019 +0800

    add file1

commit 5991ab4dc29acb187c83533f580141be9c9140f6
Author: hzp <root@foundation11.ilt.example.com>
Date:   Sun Mar 31 10:37:44 2019 +0800

    add file1

commit 02661c76cfdf312c3d52849b517b2434090a1f68
Author: root <root@foundation11.ilt.example.com>
Date:   Sun Mar 31 10:32:02 2019 +0800

    add file1

 

git log --pretty=oneline

git reflog

[root@foundation11 gitdemo]# git reflog
aef1b8d HEAD@{0}: commit: add file1
5991ab4 HEAD@{1}: commit: add file1
02661c7 HEAD@{2}: commit (initial): add file1
[root@foundation11 gitdemo]# git log --pretty=oneline
aef1b8d45c5d8d3692b6c4866480b17101c0ff4b add file1
5991ab4dc29acb187c83533f580141be9c9140f6 add file1
02661c76cfdf312c3d52849b517b2434090a1f68 add file1

版本回滚

git reset --hard HEAD^

HEAD is now at 5991ab4 add file1
[root@foundation11 gitdemo]# git reflog^C
[root@foundation11 gitdemo]# cat file1
file1

 

也可指定

[root@foundation11 gitdemo]# git reflog
5991ab4 HEAD@{0}: reset: moving to HEAD^
aef1b8d HEAD@{1}: commit: add file1
5991ab4 HEAD@{2}: commit: add file1
02661c7 HEAD@{3}: commit (initial): add file1
[root@foundation11 gitdemo]# git reset --hard 5991ab4
HEAD is now at 5991ab4 add file1

误删

rm -fr file1

git checkout --file1

 

提交删除

git rm file1

git commit -m "del file1"

也可以返回

git reflog  找到删除之前的id

git reset --hard   86e1f9b

[root@foundation11 gitdemo]# git rm file1
rm 'file1'
[root@foundation11 gitdemo]# git commit -m "rm file1"
[master 2b74495] rm file1
 Committer: hzp <root@foundation11.ilt.example.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 deletion(-)
 delete mode 100644 file1

[root@foundation11 gitdemo]# ls
file2

[root@foundation11 gitdemo]# git reflog
2b74495 HEAD@{0}: commit: rm file1
5991ab4 HEAD@{1}: reset: moving to HEAD^
aef1b8d HEAD@{2}: commit: add file1
5991ab4 HEAD@{3}: commit: add file1
02661c7 HEAD@{4}: commit (initial): add file1

[root@foundation11 gitdemo]# git reset --hard 5991ab4
HEAD is now at 5991ab4 add file1
[root@foundation11 gitdemo]# ls
file1  file2

上传自己的Git公共文件

 

 

[root@foundation11 ~]# cd /root/.ssh
[root@foundation11 .ssh]# cat
authorized_keys  id_rsa           id_rsa.pub       known_hosts      
[root@foundation11 .ssh]# cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCiB04UHHXhirqToLFm8PRu5bNqmRpPFS5XbE/IlmlpGNlbygGustR+AfKJJkOXowYkPPrDZjgEgw51DZg7BdbCVP19i4kkbmyt47UtmDZepLLkSUS6wxv+KZ01KatRX5uR2y9oqABENkDu3CF83gKKSG76Xa2dlxPMkUH7nuqAPILAWtjsrZ6t/8fCP9ub7LBTKiC2gkbzAYhPgNu3k+bzb30dcL6uESr9JLM08tKdL26E03k1rBL4pSUxGeUmTdmCX+ct7tyQOdKr9vTV4+t4Wg/gsxeScnb+aK9qvZpUvnN6kpxFqWG8yOs86EnGqVMhQhbxcTqFvJswLw3MiRKh root@foundation11.ilt.example.com

上传公钥

 

https://github.com/settings/ssh/new

 

[root@foundation11 gitdemo]# echo "# demo" >> README.md
[root@foundation11 gitdemo]# git init
Reinitialized existing Git repository in /root/gitdemo/.git/
[root@foundation11 gitdemo]# git add README.md
[root@foundation11 gitdemo]# git commit -m "first commit"
[master b48ab30] first commit
 Committer: hzp <root@foundation11.ilt.example.com>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:

    git config --global user.name "Your Name"
    git config --global user.email you@example.com

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 1 file changed, 1 insertion(+)
 create mode 100644 README.md
[root@foundation11 gitdemo]# git remote add origin git@github.com:heathcliffffffffs/demo.git
[root@foundation11 gitdemo]# git push -u origin master
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts.
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (9/9), 733 bytes | 0 bytes/s, done.
Total 9 (delta 0), reused 0 (delta 0)
To git@github.com:heathcliffffffffs/demo.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.

 

新建仓库

点上初始化的命令

[root@foundation11 gitdemo]# git remote -v
origin    git@github.com:heathcliffffffffs/demo.git (fetch)
origin    git@github.com:heathcliffffffffs/demo.git (push)

[root@foundation11 ~]# git clone git@github.com:heathcliffffffffs/test.git
Cloning into 'test'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.

[root@foundation11 ~]# cd test/
[root@foundation11 test]# ls
README.md

[root@foundation11 test]# cat README.md
# test
test

 

建立私有仓库

https://mirrors.tuna.tsinghua.edu.cn/

下载

gitlab-ce

yum install gitlab-ce-11.2.0-ce.0.el7.x86_64.rpm  -y

 

[root@foundation11 gitlab]# vim gitlab.rb
[root@foundation11 gitlab]# pwd
/etc/gitlab

external_url 'http://172.25.11.250'

重载服务

gitlab-ctl reconfigure

gitlab-ctl start

[root@foundation11 gitlab]# gitlab-ctl start
ok: run: alertmanager: (pid 14228) 35s
ok: run: gitaly: (pid 14154) 36s
ok: run: gitlab-monitor: (pid 14176) 36s
ok: run: gitlab-workhorse: (pid 14137) 37s
ok: run: logrotate: (pid 13395) 95s
ok: run: nginx: (pid 14453) 0s
ok: run: node-exporter: (pid 13681) 83s
ok: run: postgres-exporter: (pid 14261) 35s
ok: run: postgresql: (pid 12842) 160s
ok: run: prometheus: (pid 14207) 35s
ok: run: redis: (pid 12713) 166s
ok: run: redis-exporter: (pid 13817) 71s
ok: run: sidekiq: (pid 13204) 113s
ok: run: unicorn: (pid 13137) 119s
[root@foundation11 gitlab]# gitlab-ctl status
run: alertmanager: (pid 14228) 40s; run: log: (pid 14253) 40s
run: gitaly: (pid 14154) 41s; run: log: (pid 14246) 40s
run: gitlab-monitor: (pid 14176) 41s; run: log: (pid 14195) 41s
run: gitlab-workhorse: (pid 14137) 42s; run: log: (pid 14202) 40s
run: logrotate: (pid 13395) 100s; run: log: (pid 14203) 40s
run: nginx: (pid 14487) 0s; run: log: (pid 14204) 40s
run: node-exporter: (pid 13681) 88s; run: log: (pid 14247) 40s
run: postgres-exporter: (pid 14261) 40s; run: log: (pid 14347) 38s
run: postgresql: (pid 12842) 165s; run: log: (pid 14179) 41s
run: prometheus: (pid 14207) 40s; run: log: (pid 14221) 40s
run: redis: (pid 12713) 171s; run: log: (pid 14178) 41s
run: redis-exporter: (pid 13817) 76s; run: log: (pid 14194) 41s
run: sidekiq: (pid 13204) 118s; run: log: (pid 14181) 41s
run: unicorn: (pid 13137) 124s; run: log: (pid 14180) 41s

 

访问

http://172.25.11.250/users/sign_in

[root@foundation11 gitlab]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCiB04UHHXhirqToLFm8PRu5bNqmRpPFS5XbE/IlmlpGNlbygGustR+AfKJJkOXowYkPPrDZjgEgw51DZg7BdbCVP19i4kkbmyt47UtmDZepLLkSUS6wxv+KZ01KatRX5uR2y9oqABENkDu3CF83gKKSG76Xa2dlxPMkUH7nuqAPILAWtjsrZ6t/8fCP9ub7LBTKiC2gkbzAYhPgNu3k+bzb30dcL6uESr9JLM08tKdL26E03k1rBL4pSUxGeUmTdmCX+ct7tyQOdKr9vTV4+t4Wg/gsxeScnb+aK9qvZpUvnN6kpxFqWG8yOs86EnGqVMhQhbxcTqFvJswLw3MiRKh root@foundation11.ilt.example.com

 

 

搭建私有仓库

 

[root@foundation11 gitlab]# git clone git@172.25.11.250:westos/test123.git
Cloning into 'test123'...
The authenticity of host '172.25.11.250 (172.25.11.250)' can't be established.
ECDSA key fingerprint is 7c:15:30:2d:0b:2b:e5:ec:b8:fc:89:ca:33:b3:c9:9f.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.25.11.250' (ECDSA) to the list of known hosts.
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.

 

 1169  vim index.html
 1170  git add index.html
 1171  git commit -m "add index"
 1172  git push -u origin master

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值