环境搭建
python版本统一3.8.2
GitHub学习使用
安装git
git的命令:
-
初始化一个Git仓库,使用
git init
命令。 -
添加文件到Git仓库,分两步:
使用命令
git add <file>
,注意,可反复多次使用,添加多个文件;
使用命令
git commit -m <message>
-
HEAD
指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令
git reset --hard commit_id
;
git reset --hard HEAD^
返回上一版本,^的数量表示回到上几个版本,也可以用
HEAD-100
表示返回上100个版本 -
穿梭前,用
git log
可以查看提交历史,以便确定要回退到哪个版本 -
要重返未来,用
git reflog
查看命令历史,以便确定要回到未来的哪个版本。
git add
把文件添加进去,实际上就是把文件修改添加到
暂存区
;
git commit
提交更改,实际上就是把暂存区的所有内容
提交到当前分支
-
git status
查看暂存区的状态 -
git reset HEAD <file>
可以把暂存区的修改撤销掉,重新放回工作区,即撤销add的操作 -
想直接丢弃工作区的修改时,用命令
git checkout -- file
-
使用命令
git remote add origin git@github.com:path/repo-name.git
关联一个远程库 -
关联后,使用命令
git push -u origin master
第一次推送master分支的所有内容 -
此后,每次本地提交后,只要有必要,就可以使用命令
git push origin master
推送最新修改
-
git clone git@github.com:michaelliao/gitskills.git
克隆远程仓库 -
创建并切换到新的dev分支,
git switch -c dev
-
直接切换到已有的master分支,
git switch master
-
查看分支:
git branch
-
创建分支:
git branch <name>
-
切换分支:
git checkout <name>
或者
git switch <name>
-
创建+切换分支:
git checkout -b <name>
或者
git switch -c <name>
-
合并某分支到当前分支:
git merge <name>
-
删除分支:
git branch -d <name>
-
git merge --no-ff -m "merge with no-ff" <branch-name>
禁用fast forward -
git pull
从远程库更新本地 -
如果
git pull
提示no tracking information,则说明本地分支和远程分支的链接关系没有创建,用命令
git branch --set-upstream-to <branch-name> origin/<branch-name>
git add
git commit -m ‘’
git push