Linux代码保管仓库、Gitee仓库创建及代码提交

安装 git

yum install git

gitee创建仓库

注册账号

新建仓库

开源

复制路径

克隆到Xshell下

[root@VM-12-17-centos ~]# mkdir test
[root@VM-12-17-centos ~]# cd test
[root@VM-12-17-centos test]# ll
total 0
[root@VM-12-17-centos test]# git clone https://gitee.com/xiaoyan-c/linux.git
Cloning into 'linux'...
Username for 'https://gitee.com': xiaoyan-c
Password for 'https://xiaoyan-c@gitee.com': 
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
[root@VM-12-17-centos test]# ll
total 4
drwxr-xr-x 3 root root 4096 Jan 16 17:08 linux
[root@VM-12-17-centos test]# cd linux
[root@VM-12-17-centos linux]# ll
total 20
-rw-r--r-- 1 root root 9592 Jan 16 17:08 LICENSE
-rw-r--r-- 1 root root  949 Jan 16 17:08 README.en.md
-rw-r--r-- 1 root root 1310 Jan 16 17:08 README.md

.git就是下载了的仓库

[root@VM-12-17-centos linux]# ls -al
total 36
drwxr-xr-x 3 root root 4096 Jan 16 17:08 .
drwxr-xr-x 3 root root 4096 Jan 16 17:03 ..
drwxr-xr-x 8 root root 4096 Jan 16 17:08 .git
-rw-r--r-- 1 root root  270 Jan 16 17:08 .gitignore
-rw-r--r-- 1 root root 9592 Jan 16 17:08 LICENSE
-rw-r--r-- 1 root root  949 Jan 16 17:08 README.en.md
-rw-r--r-- 1 root root 1310 Jan 16 17:08 README.md

三板斧

git add

将代码放到刚才下载好的目录中git add .
[root@VM-12-17-centos linux]# cp ../../lesson7/* .
[root@VM-12-17-centos linux]# ll
total 64
-rw-r--r-- 1 root root 9592 Jan 16 17:08 LICENSE
-rw-r--r-- 1 root root   60 Jan 16 17:15 main.c
-rw-r--r-- 1 root root   94 Jan 16 17:15 Makefile
-rwxr-xr-x 1 root root 8360 Jan 16 21:33 myfile
-rw-r--r-- 1 root root  100 Jan 16 21:33 myfile.c
-rwxr-xr-x 1 root root 8672 Jan 16 17:15 myprocess
-rw-r--r-- 1 root root  415 Jan 16 17:15 proc.c
-rw-r--r-- 1 root root   58 Jan 16 17:15 proc.h
-rw-r--r-- 1 root root  949 Jan 16 17:08 README.en.md
-rw-r--r-- 1 root root 1310 Jan 16 17:08 README.md
[root@VM-12-17-centos linux]# git add .
[root@VM-12-17-centos linux]# git commit -m "代码"
[master 52494c5] 代码
 2 files changed, 9 insertions(+)
 create mode 100755 myfile
 create mode 100644 myfile.c

如果报错:
git config --global user.name "Your Name"
git config --global user.email "youremail@yourdomain.com
unable to auto-detect email address
进入config文件,添加
[user]
      	email=XXXXXXXXXX
        name=XXXXXX
[root@VM-12-17-centos linux]# ls -al
total 80
drwxr-xr-x 3 root root 4096 Jan 16 21:33 .
drwxr-xr-x 3 root root 4096 Jan 16 17:03 ..
drwxr-xr-x 8 root root 4096 Jan 16 21:34 .git
-rw-r--r-- 1 root root  270 Jan 16 17:08 .gitignore
-rw-r--r-- 1 root root 9592 Jan 16 17:08 LICENSE
-rw-r--r-- 1 root root   60 Jan 16 17:15 main.c
-rw-r--r-- 1 root root   94 Jan 16 17:15 Makefile
-rwxr-xr-x 1 root root 8360 Jan 16 21:33 myfile
-rw-r--r-- 1 root root  100 Jan 16 21:33 myfile.c
-rwxr-xr-x 1 root root 8672 Jan 16 17:15 myprocess
-rw-r--r-- 1 root root  415 Jan 16 17:15 proc.c
-rw-r--r-- 1 root root   58 Jan 16 17:15 proc.h
-rw-r--r-- 1 root root  949 Jan 16 17:08 README.en.md
-rw-r--r-- 1 root root 1310 Jan 16 17:08 README.md
[root@VM-12-17-centos linux]# ls -l .git
total 48
drwxr-xr-x  2 root root 4096 Jan 16 17:03 branches
-rw-r--r--  1 root root    7 Jan 16 21:34 COMMIT_EDITMSG
-rw-r--r--  1 root root  310 Jan 16 17:32 config
-rw-r--r--  1 root root   73 Jan 16 17:03 description
-rw-r--r--  1 root root   23 Jan 16 17:08 HEAD
drwxr-xr-x  2 root root 4096 Jan 16 17:03 hooks
-rw-r--r--  1 root root  840 Jan 16 21:33 index
drwxr-xr-x  2 root root 4096 Jan 16 17:03 info
drwxr-xr-x  3 root root 4096 Jan 16 17:08 logs
drwxr-xr-x 21 root root 4096 Jan 16 21:34 objects
-rw-r--r--  1 root root  107 Jan 16 17:08 packed-refs
drwxr-xr-x  5 root root 4096 Jan 16 17:08 refs

 

git commit

[root@VM-12-17-centos linux]# git commit -m "代码"
[master 52494c5] 代码
 2 files changed, 9 insertions(+)
 create mode 100755 myfile
 create mode 100644 myfile.c

上传到本地的克隆仓库

"  "括号内是对提交内容的描述,不要随便写,别人可以通过git log查看日志

[root@VM-12-17-centos linux]# git log
commit 52494c5a7dd2f8c192dad0b0c96445502da64776
Author: xiaoyan-c <1435769566@qq.com>
Date:   Mon Jan 16 21:34:41 2023 +0800

    代码

commit 4ffd424a104f1198d1a4ad78b047f287bea30749
Author: xiaoyan-c <1435769566@qq.com>
Date:   Mon Jan 16 17:32:20 2023 +0800

    进度条等代码练习

commit 783715d4b91cb3290c8e0f245d8a135530ae9267
Author: komorebi_filpped_肖 <1435769566@qq.com>
Date:   Mon Jan 16 09:00:19 2023 +0000

    Initial commit

git push

[root@VM-12-17-centos linux]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'https://gitee.com': xiaoyan-c
Password for 'https://xiaoyan-c@gitee.com': 
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 5.11 KiB | 0 bytes/s, done.
Total 11 (delta 2), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/xiaoyan-c/linux.git
   783715d..52494c5  master -> master

上传到远端仓库

 

拓展

git log

[root@VM-12-17-centos linux]# git log
commit 52494c5a7dd2f8c192dad0b0c96445502da64776
Author: xiaoyan-c <1435769566@qq.com>
Date:   Mon Jan 16 21:34:41 2023 +0800

    代码

commit 4ffd424a104f1198d1a4ad78b047f287bea30749
Author: xiaoyan-c <1435769566@qq.com>
Date:   Mon Jan 16 17:32:20 2023 +0800

    进度条等代码练习

commit 783715d4b91cb3290c8e0f245d8a135530ae9267
Author: komorebi_filpped_肖 <1435769566@qq.com>
Date:   Mon Jan 16 09:00:19 2023 +0000

    Initial commit

git rm

[root@VM-12-17-centos linux]# git rm main.c
rm 'main.c'
[root@VM-12-17-centos linux]# git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	deleted:    main.c
#
[root@VM-12-17-centos linux]# git add .
[root@VM-12-17-centos linux]# git commit -m "删除不需要的main.c代码"
[master dfa05d7] 删除不需要的main.c代码
 1 file changed, 8 deletions(-)
 delete mode 100644 main.c
[root@VM-12-17-centos linux]# git push
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)

Username for 'https://gitee.com': xiaoyan-c
Password for 'https://xiaoyan-c@gitee.com': 
Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 258 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/xiaoyan-c/linux.git
   52494c5..dfa05d7  master -> master

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值