hometownblog

1.指令集

1.1 本地与远程操作

创建文件

echo > README.md(文件名)

创建文件时输入信息

echo "(message)" >> README.md (文件名)

初始化本地仓库

git init

添加文件放入缓存流中

git add . (点"."表示添加当前文件夹全部文件,添加某个文件直接使用文件名)

克隆远程仓库

git clone 仓库地址

把缓存内容放进发送头

git commit -m "xx" (“xx”为对本次上传作的说明)

​添加remote地址

git remote add origin 新地址

查看remote地址

git remote -v

删除remote地址

git remote rm origin

拉取远程内容

git pull --rebase origin master

提交至远程

git push (-u) origin 分支名 (-f) (第一次提交加上-u,强行提交忽略远程修改加-f)

1.2 分支相关

新建分支

git branch 新分支名 (SHA值)(如果新建的分支是某个分支的拷贝,需加上SHA值,该值可在git log中找到)

修改当前分支名

git branch -M main(新分支名)(参数-M跟-m区别:前者即便新的分支名已经存在也会修改,后者则不会)

删除分支

git branch -D main(分支名)

查看分支状态

git status

切换分支

git checkout 分支名

1.3 历史相关

允许合并不相关历史

git pull --allow-unrelated-histories

查看历史提交

git log (输出最后如果是':',按'q'即可退出)

2.常见操作

2.1 本地初始化仓库并提交

git init
echo >README.md
git add .//git add README.md
git commit -m "submit README.md"
git remote add origin 仓库地址
git push -u origin master(分支名)

2.2 修改remote地址

git remote -v
git remote rm origin
git remote add origin 仓库地址

2.3 切回历史分支

2.3.1 不新建分支型

git log
git checkout 分支名

2.3.2 新建分支型

git log(记下对应分支的SHA值)
git branch 新分支名 (SHA值)
git checkout 新分支名

相关文章:

  • 2021-09-18
  • 2021-12-06
  • 2021-11-30
  • 2021-11-13
  • 2021-12-03
  • 2021-12-06
  • 2021-04-07
  • 2021-05-19
猜你喜欢
  • 2021-09-09
  • 2021-06-18
  • 2021-10-19
  • 2021-05-11
  • 2021-12-25
  • 2021-04-02
  • 2021-09-11
  • 2022-01-13
相关资源
相似解决方案