學會使用碼雲管理檔案
阿新 • • 發佈:2019-01-05
使用碼雲帶來的好處:
- 程式碼共享
- 檔案恢復
- 原始碼維護
- 版本控制
常見版本控制系統有Git、SVN、CVS、Git、Mercurial,目前主流使用的最多的就是git和svn,下面是這兩種版本控制系統的比較:
- GIT是分散式的,SVN是集中式管理;
- GIT把內容按元資料方式增量儲存,而SVN是按檔案; <.svn .git >
- GIT分支和SVN的分支不同;
- GIT的內容完整性要優於SVN:
- git內容儲存使用的是SHA-1雜湊演算法;
- SVN有一個全域性的整數編號,而git則是一個SHA-1值作編號:
- SVN控制粒度可以到某個目錄(當然很少這樣做);而git一般是整個專案;
一、建立專案
1. 點選“+”->"新建專案"
2. 填寫歸屬->填寫名稱->路徑自動匹配->介紹(非必填)->選擇程式語言(如C)->新增.gitignore->加密方式(如GPL v2)->相應填寫是否公開->儲存
3. (可選)開啟svn訪問:點進專案->管理->基本設定->啟用svn訪問
二、公鑰管理
開發者向碼雲版本庫寫入最常用到的協議是 SSH 協議,因為 SSH 協議使用公鑰認證,可以實
現無口令訪問,而若使用 HTTPS 協議每次身份認證時都需要提供口令。
1.若伺服器沒有安裝git服務,首先安裝
[root@VM_83_82_redhat ~]# yum install git git-gui
2.對git進行全域性配置
[yanhuan@VM_83_82_redhat ~]$ git config --global user.name"yanhuan"
[yanhuan@VM_83_82_redhat ~]$ git config --global user.email"*****@foxmail.com"
//使用者名稱和郵箱應為自己實際姓名而非登入名
3.生成SSH祕鑰
[[email protected]_83_82_redhat ~]$ ssh-keygen -t rsa -C "*****@foxmail.com" //對應上方郵箱
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yanhuan/.ssh/id_rsa): //選擇祕鑰儲存路徑
Created directory '/home/yanhuan/.ssh'.
Passphrases do not match. Try again.
Enter passphrase (empty for no passphrase): //linux賬號的密碼
Enter same passphrase again:
Your identification has been saved in /home/yanhuan/.ssh/id_rsa.
Your public key has been saved in /home/yanhuan/.ssh/id_rsa.pub.
The key fingerprint is:
3b:2b:69:61:f1:40:77:c0:3a:ff:e8:07:3f:58:1c:cd *****@foxmail.com
The key's randomart image is:
+--[ RSA 2048]----+
| ... |
| . o . |
| . o . o |
| = . E |
| *S. . |
| o +.o |
| . ooB |
| + oo= |
| . oo. . |
+-----------------+
4.上傳祕鑰到碼雲
[[email protected]_83_82_redhat ~]$ cat ~/.ssh/id_rsa.pub //檢視祕鑰檔案
ssh-rsa AAAA************705R2UZ ******@foxmail.com
設定->SSH公鑰->新增
5.測試是否連上SVN
[[email protected]_83_82_redhat ~]$ ssh -T [email protected]
The authenticity of host 'git.oschina.net (120.55.226.24)' can't be established.
ECDSA key fingerprint is 27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.oschina.net,120.55.226.24' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/yanhuan/.ssh/id_rsa': //linux密碼
Welcome to Gitee.com, yanhuan! //成功
[[email protected]_83_82_redhat ~]$
三、下載
1.git下載
[[email protected]_83_82_redhat ~]$ git clone [email protected]:************.git
Cloning into 'FL2440KaiFaBan'...
The authenticity of host 'gitee.com (120.55.226.24)' can't be established.
ECDSA key fingerprint is 27:e5:d3:f7:2a:9e:eb:6c:93:cd:1f:c1:47:a3:54:b1.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com' (ECDSA) to the list of known hosts.
Enter passphrase for key '/home/yanhuan/.ssh/id_rsa':
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), 6.93 KiB | 0 bytes/s, done. //git下載成功
2.svn下載
注意: 在碼雲上使用git管理的專案,svn不能管理空資料夾,只能管理檔案:
[root@VM_83_82_redhat ~]# yum install subversion //首先要有svn
[yanhuan@VM_83_82_redhat ~]$ svn co svn://gitee.com/********** //svn下載地址
Authentication realm: <svn://gitee.com:3690> gitee.com
Password for 'yanhuan': //linux密碼
Authentication realm: <svn://gitee.com:3690> gitee.com
Username: *******@qq.com //碼雲註冊郵箱
Password for '********@qq.com': //碼雲密碼
Authentication realm: <svn://gitee.com:3690> gitee.com
Username: ******@qq.com
Password for '*******@qq.com':
Store password unencrypted (yes/no)? yes
C FL2440KaiFaBan/LICENSE
C FL2440KaiFaBan/README.md
Checked out revision 1. //revision 1下載成成功
[yanhuan@VM_83_82_redhat ~]$ ^C
[yanhuan@VM_83_82_redhat ~]$ ls
FL2440KaiFaBan
[yanhuan@VM_83_82_redhat ~]$ ls
FL2440KaiFaBan
[yanhuan@VM_83_82_redhat ~]$ ls FL2440KaiFaBan/
LICENSE README.md
四、git上傳
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ git config --global user.name "yanhuan"
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ git config --global user.email "*******@foxmail.com"
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ ls crosstool/
build.sh
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ git add crosstool/ //git上傳crosstoll
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ git commit -m"Add crosstool build shell script" //註釋
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ git push //push上碼雲
Enter passphrase for key '/home/yanhuan/.ssh/id_rsa': //linux密碼
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 611 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To git@gitee.com:yanyanhuan/FL2440KaiFaBan.git
e172c5b..d442979 master -> master
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ git checkout . //git同步下載
五、svn上傳
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ svn add crosstool/ //svn上傳crosstool
A crosstool
A crosstool/build.sh
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ svn ci -m"Add crosstool build shell script" //註釋
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ svn diff //比較
[yanhuan@VM_83_82_redhat FL2440KaiFaBan]$ svn up //svn同步