emm~~一直没有管理代码的不良习惯,自从服务器突然崩了,代码都没了,我觉得是时候好好管理一下了!!!进入正题:
1. 注册github账号 邮箱 ([email protected])+ 密码
2. 获取SSH Key的秘钥对
本地执行:ssh-****** -t rsa -C "[email protected]"
会得到:id_rsa是私钥,不能泄露出去,id_rsa.pub是公钥,可以告诉别人
3. 登陆github,添加公钥,建立链接
登陆—>点击"settings"—>点击"SSH Keys"—>点击"New SSH Key"–填上任意Title,在Key文本框里粘贴id_rsa.pub文件的内容—>点击"Add key"
4. 创建远程仓库
“your repositories” ---->依次填写图中信息---->“create repository”
5. 从github初始化本地项目
如:git clone [email protected]:yangyang12315/pytorch_tool.git
6. 本地代码上传到github—先从本地提交到本地暂存区,再从本地暂存区提交到githubgit add file.py #在本地仓库添加文件【如果是文件夹,要写入文件(file.py自己本地创建)】git commit -m "creat first" :将本地提交到临时仓库 “creat first”是对本操作说明git push:将本地临时仓库里面代码 提交到 github #实现更新
7. github代码拉倒本地git pull :从github上拉去代码到本地
###############################################################
其他常用功能:
1. 恢复版本 – 先从github上恢复到本地暂存区,再从本地暂存区恢复到本地git reset 版本号 (HEAD) :HEAD 表示当前版本 HEAD尖号:表示上一个版本git checkout 文件名(tsm_utils.py)
2. 查看日志:git log
3. 配置用户名:
git config --global user.email "[email protected]"
git config --global user.name “cqSpringLee”
4. 修改远程仓库
克隆远程仓库到本地库。【注意先备份本地文件/本地文件换个名字】
克隆代码到本地:git clone [email protected]:xxx/xxx.git
删除文件:git rm test.txt
提交修改:git commit -m "Delete."
将修改提交到远程仓库的xxx分支: git push
5. 删除github上的整个项目
“your repositories” —> “pytorch_tools”[你要删除的项目] ---->“settings” ---->“Delete this repository”