git版本控制在centos系统的安装与使用,包括下拉pull,增删修改目录文件以及他们的上传到github

前言:首先要安装git,centos使用yum install git 就可以安装,git --version查看版本号
#ssh-keygen -t rsa -C "[email protected]"生成公钥,这个-C的参数是注释,可以是你的github的注册邮箱账户邮箱名,当然如果不是也可以正常,随便一个字符串都行。
[root@iZ5361zrqbnxubZ test3]# ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa. #这里是私钥文件
Your public key has been saved in /root/.ssh/id_rsa.pub.#这里是公钥文件
The key fingerprint is:
SHA256:MiS0ZXh0RJCLvgk6sv98pfbMDhMv6/okSHhP8lXfdvk [email protected]
The key’s randomart image is:
±–[RSA 2048]----+
| .o==+ |
| …+o. |
| oo… |
| . .o… . . . |
|. +… = S . o o |
| o.… =. . . . |
| …+o=o. E|
|+ .oo+B |
|o+…+
+o= |
±—[SHA256]-----+
[root@iZ5361zrqbnxubZ test3]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDDS/Rfzq19xKfvr9aqac9vnQ7f2744ArC/x1t6veDG6usCqBqCEmVUwEhrfkeW99f3BSfqxUpLvhxHUQt7r5VaLNiqUUIr/K1qkCj62cH56Bod+DmYnpnAt01jLrE8+DfFDnVZjYH4lbNqGJRUKS2A/L+1XHvpAPHV424vDdaJhQGdYrNLo5kqueBsDNc4h66t82m/i1PN6c1L7wtCXyTJ4xq/NcankZ1w8KBjPTFOeKRHpZBK5piMD6PXw9kMlLR3VIxlo6he9mvvkXJwt0TbQYZvzJkgie9u0dxfH7t9qbjZoqIfXlQPtfVZvBVzVLa9Bj2X9kar5xZ+oadn/nxf [email protected]
#将该公钥复制到github对应的你要对应的那个仓库的设置set界面中有一个key,然后选择add key 复制到这里,用于,秘钥验证认证上传push代码
[root@iZ5361zrqbnxubZ test3]# mkdir test5
[root@iZ5361zrqbnxubZ test3]# cd test5
[root@iZ5361zrqbnxubZ test3]# git init
#添加远程库,该仓库地址在github仓库代码下载页面中有,复制即可。
[root@iZ5361zrqbnxubZ test3]# git remote add origin https://github.com/githubismylove/bestmvc.git

[root@iZ5361zrqbnxubZ test5]# git pull origin master #必须首先执行这个,否则后面执行git push master会报403错,可能是因为没有建立README.MD的原因
remote: Enumerating objects: 19, done.
remote: Counting objects: 100% (19/19), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 19 (delta 4), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (19/19), done.
From https://github.com/githubismylove/bestmvc

  • branch master -> FETCH_HEAD

[root@iZ5361zrqbnxubZ test5]# vim a.txt
[root@iZ5361zrqbnxubZ test5]# git add a.txt
[root@iZ5361zrqbnxubZ test5]# git commit -m ‘first’
[master 144c051] first
1 file changed, 1 insertion(+)
create mode 100644 a.txt
[root@iZ5361zrqbnxubZ test5]# git push origin master#注意下面的邮箱账户,该邮箱应该在github的setting页面的Emails选项页面的Keep my email address private
选项复选框不要打钩,否则会报错。
Username for ‘https://github.com’: [email protected]
Password for ‘https://[email protected]@github.com’:
Counting objects: 4, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/githubismylove/bestmvc.git
594eeef…144c051 master -> master

[root@iZ5361zrqbnxubZ test5]# git rm app.js #删除文件
rm ‘app.js’
[root@iZ5361zrqbnxubZ test5]# ll
total 128
-rw-r–r-- 1 root root 5 Jul 1 22:37 a.txt
-rw-r–r-- 1 root root 2 Jul 1 22:33 index.pug
-rw-r–r-- 1 root root 382 Jul 1 22:33 package.json
-rw-r–r-- 1 root root 110424 Jul 1 22:33 package-lock.json
-rw-r–r-- 1 root root 114 Jul 1 22:33 README.md
-rw-r–r-- 1 root root 32 Jul 1 22:33 template.pug
[root@iZ5361zrqbnxubZ test5]# git commit -m ‘delete app.js file’ #提交到本地缓存
[master a0936db] delete app.js file
1 file changed, 151 deletions(-)
delete mode 100644 app.js
[root@iZ5361zrqbnxubZ test5]# git push origin master#将修改提交到github服务器
Username for ‘https://github.com’: [email protected]
Password for ‘https://[email protected]@github.com’:
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 230 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/githubismylove/bestmvc.git
144c051…a0936db master -> master
[root@iZ5361zrqbnxubZ test5]# ll
total 128
-rw-r–r-- 1 root root 5 Jul 1 22:37 a.txt
-rw-r–r-- 1 root root 2 Jul 1 22:33 index.pug
-rw-r–r-- 1 root root 382 Jul 1 22:33 package.json
-rw-r–r-- 1 root root 110424 Jul 1 22:33 package-lock.json
-rw-r–r-- 1 root root 114 Jul 1 22:33 README.md
-rw-r–r-- 1 root root 32 Jul 1 22:33 template.pug
[root@iZ5361zrqbnxubZ test5]# git mv index.pug index.html #重命名一个文件
[root@iZ5361zrqbnxubZ test5]# git status

On branch master

Changes to be committed:

(use “git reset HEAD …” to unstage)

renamed: index.pug -> index.html

[root@iZ5361zrqbnxubZ test5]# git commit -m ‘rename index.pug file’
[master f8dc621] rename index.pug file
1 file changed, 0 insertions(+), 0 deletions(-)
rename index.pug => index.html (100%)

[root@iZ5361zrqbnxubZ test5]# ll
total 128
-rw-r–r-- 1 root root 5 Jul 1 22:37 a.txt
-rw-r–r-- 1 root root 2 Jul 1 22:33 index.html
-rw-r–r-- 1 root root 382 Jul 1 22:33 package.json
-rw-r–r-- 1 root root 110424 Jul 1 22:33 package-lock.json
-rw-r–r-- 1 root root 114 Jul 1 22:33 README.md
-rw-r–r-- 1 root root 32 Jul 1 22:33 template.pug
[root@iZ5361zrqbnxubZ test5]# git push origin master
Username for ‘https://github.com’: [email protected]
Password for ‘https://[email protected]@github.com’:
Counting objects: 3, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 237 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/githubismylove/bestmvc.git
a0936db…f8dc621 master -> master

[root@iZ5361zrqbnxubZ test5]# vim a.txt #使用linux本地命令修改文件
[root@iZ5361zrqbnxubZ test5]# git status

On branch master

Changes not staged for commit:

(use “git add …” to update what will be committed)

(use “git checkout – …” to discard changes in working directory)

modified: a.txt

no changes added to commit (use “git add” and/or “git commit -a”)
[root@iZ5361zrqbnxubZ test5]# rm -f package.json #使用linux本地命令删除文件
[root@iZ5361zrqbnxubZ test5]# git status

On branch master

Changes not staged for commit:

(use “git add/rm …” to update what will be committed)

(use “git checkout – …” to discard changes in working directory)

modified: a.txt

deleted: package.json

no changes added to commit (use “git add” and/or “git commit -a”)
[root@iZ5361zrqbnxubZ test5]# vim three.txt #使用linux本地命令新增文件
[root@iZ5361zrqbnxubZ test5]# git status

On branch master

Changes not staged for commit:

(use “git add/rm …” to update what will be committed)

(use “git checkout – …” to discard changes in working directory)

modified: a.txt

deleted: package.json

Untracked files:

(use “git add …” to include in what will be committed)

three.txt

no changes added to commit (use “git add” and/or “git commit -a”)

[root@iZ5361zrqbnxubZ test5]# git add --all . #注意,必须加入该命令,该命令可以将linux命令rm,vim,mv等等所有的更改都提交到本地仓库中,如果不加,那么commit命令不会提交这些修改到本地仓库。还有就是–all要加上,否则从git2.0之后,默认是add提交是不提交删除动作的,所以要加上,文档是这样说的。
[root@iZ5361zrqbnxubZ test5]# git status

On branch master

Changes to be committed:

(use “git reset HEAD …” to unstage)

modified: a.txt

deleted: package.json

new file: three.txt

[root@iZ5361zrqbnxubZ test5]# git commit -m ‘all change’
[master 63d7089] all change
3 files changed, 2 insertions(+), 24 deletions(-)
delete mode 100644 package.json
create mode 100644 three.txt
[root@iZ5361zrqbnxubZ test5]# git push origin master
Username for ‘https://github.com’: [email protected]
Password for ‘https://[email protected]@github.com’:
Counting objects: 6, done.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 323 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/githubismylove/bestmvc.git
f8dc621…63d7089 master -> master
–河北强商网络科技有限公司技术支持–

发布了16 篇原创文章 · 获赞 0 · 访问量 673

猜你喜欢

转载自blog.csdn.net/yaqiang2017/article/details/94415727