由于实验室提供的服务器资源实在是不够用,于是考虑暂时性的租用服务器,找到了一个适合学生的服务器租用网站(便宜),其推荐上传代码的方式就是通过github
,于是我开启了第一次github
项目上传之旅…
- 首先是一些傻瓜操作(我将不使用命令的,通过图形界面完成的操作称为傻瓜操作):
- 在github首页点击左边的
New
按钮,根据自己的需求新建一个repository
- 建好之后,利用
git clone
命令将这个repository
下载到需要的位置 - 进入下载好的文件夹内部,将需要上传的文件拷贝到这里
- 最后使用以下的
git
命令,完成上传:
git add .
将项目添加到仓库,此处的.
代表将此文件夹下的所有文件上传,也可以换为filename
,即你想上传的文件名称
git commit -m "提交信息"
把项目提交到仓库,这里的提交信息
相当于一个注释,相当于你为这次提交取的名字,可以换为自己想取的名字
但第一次输入这行命令的时候,出现错误:
** Please tell me who you are.
Run
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
to set your account's default identity.
Omit --global to set the identity only in this repository.
fatal: unable to auto-detect email address (got 'Anita@newton.(none)')
这里可能只是为了验证你的信息,只需要按照他的要求依次输入这两行命令即可:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git push origin
将本地项目推送到远程仓库(即github
),但是这一步非常神奇,有人写为git push -u origin master
,有人写为git push origin master
,这两种我试过了,都会报错,报错信息是:
error: src refspec master does not match any.
error: failed to push some refs to 'git@github.com:hahaha/ftpmanage.git'
这个信息的意思是目前不能将一些引用推到你要上传的github
位置,也就是目前仓库为空,假如仓库真的为空,就需要执行上面的git commit
命令,但是我使用了git commit
命令之后,就出现了下面这个报错
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
这句话的意思是说目前已经有一个提交了,需要使用git push
命令把之前的这个提交推到github
上,因此证明我的仓库并不是空的,之前的报错信息有误…
最后也没搞清楚到底是哪里出了问题,但是换成git push origin
之后立马成功(摊手)
因此,这部分一共需要使用三个git
命令:
git add .
git commit -m "提交信息"
git push origin
- Private Repository
如果大家要上传的Repository是私密的话,那么在输入使用git
命令下载和上传时,有时会出现需要身份验证的地方,如下:
Username for 'https://github.com': YasmineXXX
Password for 'https://shliang0603@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: unable to access 'https://github.com/YasmineXXX/CrossModalTransformer.git/': The requested URL returned error: 403
这个提示的意思大致是说,github
修改了验证规则,从密码改为了token
,而这个token
需要自己设置,改为这种方式的原因以及具体设置的方式这里就不细说了,具体可以参考下面这篇文章:
https://blog.csdn.net/weixin_41010198/article/details/119698015
跟着这篇文章设置好token
后,在每个需要输入密码的位置输入token
就可以啦
最后是成功后的提示:
Username for 'https://github.com': YasmineXXX
Password for 'https://YasmineXXX@github.com':
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 64 threads
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 390.60 KiB | 3.40 MiB/s, done.
Total 18 (delta 0), reused 0 (delta 0)
To https://github.com/YasmineXXX/CrossModalTransformer.git
8eb2b01..aaacff3 main -> main
8.23更
感觉这种使用命令行的方式上传代码有些麻烦,周五跟朋友聊天得知,github有一个方便操作的傻瓜软件,查了一下发现,叫GitHub Desktop
,但是只有windows
和mac
版本的,linux
暂时没有官方版本,但是我觉得也挺方便了hh(可以将linux
的命令行和windows
的desktop
结合使用)
简单说一下使用方法,首先登录个人账户,成功之后在工具栏的File
下就可以创建新的repo
,或者将已有的repo
复制下来:
建好repo之后,就只需要分别学习这三个命令行对应的操作了:
git add .
git commit -m "提交信息"
git push origin
git add.
需要找到GitHub在本地存储repo
的位置,不知道的话,可以在新建repo
的界面查看:
在这个位置下,就可以根据需求放入或者删除文件了
git commit -m "提交信息"
在加入或删除文件之后,github
会自动生成改动信息,非常详细,详细到某个文件的某行代码的删除或添加,点击界面左侧的Changes
就可以看到:
然后在左下角写好改动的提炼(Summary)和描述(Description),再点击Commit to main
(有时是Commit to master
,不晓得什么区别)就可以提交这个改动了
git push origin
最后,点击Push origin
按钮,就可以上传到远程了
使用这种傻瓜软件的好处:
- 对于私有库的处理非常方便,验证在最初登录个人账户时就完成了,不需要额外进行用户或token的验证了
- 基本上没出现过网络问题,但是使用命令行时,经常会因为网络问题需要重复操作
- 最直接的,傻瓜操作,比较容易上手
踩坑总结结束,为看到的铁汁们铺路。参考文章:
如何使用git上传项目到github(简单的方法) - HEternally的文章 - 知乎
https://zhuanlan.zhihu.com/p/28062574
https://blog.csdn.net/milijiangjun/article/details/116161334
https://blog.csdn.net/qq_38198952/article/details/82792279
https://blog.csdn.net/weixin_41010198/article/details/119698015
https://blog.csdn.net/artechtor/article/details/108145517