常用git指令记录

mac2022-06-30  92

Generating an SSH key Checking for existing SSH keysGenerating a new SSH key and adding it to the ssh-agentAdding a new SSH key to your GitHub accountTesting your SSH connection   设置username和email $ git config --global user.name "your name"          //配置用户名 $ git config --global user.email your_email@youremail.com  //配置用户邮箱 $ git config --global credential.helper store  //保存用户名和密码 避免每次提交都要输入的麻烦

 

创建并初始化本地仓库 $ mkdir my_test              //创建my_test文件夹 $ cd my_test                //进入my_test文件夹 $ git init //初始化本地版本库 ,该命令之后,项目被添加到暂存区,然后必须利用git的命令提交 $ git rm -r --cached ./.gitignore //如果是后改动.gitignore文件,需要先清除缓存,然后再更新该文件 $ git add ./.gitignore //添加过滤规则 $ git commit -m "update .gitignore" //添加提交记录

 

推送本地仓库到远程仓库 $ git push -u origin master //由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。

 

从远程仓库clone $ git clone https://github.com/RT-Thread/rt-thread.git   分支操作 $ git branch        //查看分支 $ git branch test      //创建分支test $ git branch test1 b49afc //从指定节点创建分支test1 $ git checkout test //切换到test分支 $ git merge test1      //合并test1的修改到test分支 $ git branch -d test1          //删除本地test1分支 $ git branch -r -d origin/test1   //删除远程分支test1 步骤1 $ git push origin :test1   //删除远程分支test1 步骤2 $ git branch -m test my_test    //重命名本地分支test为my_test

 

标签操作 $ git tag v1.2       //对当前提交创建轻量标签 $ git tag v1.2 -m "xxxxx"   //对当前提交创建附注标签 $ git tag v1.2 9fbc360   //对指定commit创建标签 $ git push origin v1.2 //推送tag v1.2到远程仓库

 

撤销上次提交 $ git revert 8008ea //撤销8008ea的修改 内容恢复到上次提交 该次改动要作为一次commit commit内容填写为什么要撤销

 

远程仓库fork分支和远程源仓库分支进行同步 $ git remote add upstream https://github.com/RT-Thread/rt-thread.git//添加远程源分支$ git remote -v          //查看远程仓库分支 $ git fetch upstream     //更新远程源仓库的更改到本地仓库 $ git merge upstream/master //合并远程源仓库的master分支的更改到本地仓库的当前分支 $ git push origin master   //推送本地当前分支到远程master分支

转载于:https://www.cnblogs.com/emlslxl/p/8464935.html

最新回复(0)