本学期为了更好在专业8号机房上课,配合机房的管理规定,机房机子不能存储任何文件,想到了用github,记录如下:
1、到github的网站创建自己的仓库dscom2020,其他的都默认,看清下面的说明
2、打开终端,切换到tmpCode目录,克隆仓库:git clone https://github.com/guochaoxxl/dscom2020.git
3、切换目录:cd dscom2020
4、新建文件README.md和testc.c
echo "# dscom2020" >> README.md //创建并写入文件
testc.c文件内容:
1 #include <stdio.h> 2 #include <stdbool.h> 3 #include <string.h> 4 5 #define Size 10 6 7 int main(int argc, char **argv) 8 { 9 printf("Hello world! "); 10 11 for(int i = 0; i < argc; i++){ 12 printf("%dth: %s ", i + 1, *(argv + i)); 13 } 14 printf(" "); 15 16 int var1 = 33; 17 printf("var1: %d ", var1); 18 printf("&var1: %p ", &var1); 19 20 int *ptrVar1; 21 ptrVar1 = &var1; 22 printf("ptrVar1: %p ", ptrVar1); 23 printf("&ptrVar1: %p ", &ptrVar1); 24 printf("*ptrVar1: %d ", *ptrVar1); 25 26 printf("*ptrVar1: %d ", ++*ptrVar1); 27 printf("var1: %d ", var1); 28 printf("&var1: %p ", &var1); 29 30 const int var2 = 99; 31 printf("var2: %d ", var2); 32 33 int *ptrVar2 = &var2; 34 printf("*ptrVar2: %d ", ++*ptrVar2); 35 printf("var2: %d ", var2); 36 37 /* struct _stu{ 38 int id; 39 bool sex; 40 char name[Size]; 41 }; 42 43 struct _stu stu1;*/ 44 45 //typedef struct _stu{ 46 typedef struct { 47 int id; 48 bool sex; 49 char name[Size]; 50 } Student; 51 52 Student stu1; 53 54 stu1.id = 1001; 55 stu1.sex = 0; 56 // stu1.name = "zhangsan"; 57 strcpy(stu1.name, "zhangsan"); 58 59 printf("student info: name-%s sex-%d id-%d ", stu1.name, stu1.sex, stu1.id); 60 61 Student *ptrStu1 = &stu1; 62 (*ptrStu1).id = 1002; 63 (*ptrStu1).sex = 1; 64 strcpy((*ptrStu1).name, "lisi"); 65 66 printf("student info: name-%s sex-%d id-%d ", ptrStu1->name, ptrStu1->sex, ptrStu1->id); 67 68 return 0; 69 }
5、提交到缓冲区:git add README.md testc.c
6、提交到本地仓库:git commit -m "first commit"
7、配置git:
git config --global user.name "guochaoxxl"
git config --global user.email "guochaoxxl@163.com"
git config --global color.ui true
git config --global core.editor "vim"
8、提交时,出现错误:
git push
Username for 'https://github.com': guochaoxxl
Password for 'https://guochaoxxl@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: 'https://github.com/guochaoxxl/dscom2020.git/' 鉴
9、创建token
登录github帐号,点击自己的头像,点击Setting--> Developer settings -->Personal access tokens-->Generate new token-->Give your token a descriptive name
-->select the Expiration drop-down menu, then click a default or use the calendar picker-->Select the scopes, or permissions, you'd like to grant this token. To use your token to access repositories from the command line, select repo.
-->Generate token-->rember your token like your password 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_X
10、使用token
git push 时,git push
Username for 'https://github.com': guochaoxxl
Password for 'https://guochaoxxl@github.com': 把自己刚才的token内容粘贴就好,有点坑的是密码时没有任何反响,我一致以为没有成功
枚举对象中: 4, 完成.
对象计数中: 100% (4/4), 完成.
使用 4 个线程进行压缩
压缩对象中: 100% (3/3), 完成.
写入对象中: 100% (4/4), 731 字节 | 731.00 KiB/s, 完成.
总共 4(差异 0),复用 0(差异 0),包复用 0
To https://github.com/guochaoxxl/dscom2020.git
* [new branch] master -> master
OK成功了,大工告成,搞定了。