【学习笔记】Git

393 阅读2分钟

参考文献:

juejin.im/post/684490…

Git链接到自己的Github

  1. 首先需要将本地的SSH新增到你的Github账号下的SSH中。 本地生成SSH指令如下:

    ssh-keygen -t rsa -C "abcd@efgh.com" //邮箱同上

默认一直回车,打开保存的文件——id_rsa.pub的文件,复制粘贴到github你的账号下面的ssh中。 2. 新建项目,通过本地新建或直接github下新建respository,大同小异,具体指令分别如下: - 本地新建

		mkdir helloworld
      cd helloworld
      git init //将helloworld文件夹变为本地仓库,可以将需要上传的文件拖到helloworld文件夹里
      git remote add origin https:github.com/[your 账号名]/helloworld.git
      git push -u origin master
  如果这里有报错,请参考博文<https://blog.csdn.net/Alex__0_0/article/details/105808710>
- github新建respository项目,在本地输入以下代码克隆远程项目,并提交readme文件,具体指令如下:

		mkdir helloworld    
 		cd helloworld
      git init
      touch README
      git add README
      git commit -m "first commit"
      git remote add origin https:github.com/[your 账号名]/helloworld.git
      git push -u origin master     

Git常见指令

指令作用
mkdir [project-name]创建文件夹
git int [project-name]初始化目录,会出现.git文件
git clone [url]下载项目和整个代码历史
git add [文件]/*添加暂存区文件/或全部文件到本地仓库
git add -p添加每个变化前,都会要求确认.对于同一个文件的多处变化,可以实现分次提交
git rm [file1] [file2]删除工作区文件,并且将这次删除放入暂存区
git mv [file-original] [file-renamed]
git commit -m [message]
git commit -a
git commit -v
git commit --amend -m [message]
git push origin master
git pull origin master
--分支----Branch-多人协作-
git branch
git branch -r
git branch -a
git branch [new branch_name]
git branch -b [new branch_name]
git checkout [branch-name]
git checkout -
git merge [branch]
git cherry-pick [commit]
git branch -d [branch-name]
git push origin --delete [branch-name] git branch -dr [remote/branch]
--标签----Tags-版本回退-
git tag
git tag [tag]
git tag -d [tag]
git show tag
git push [remote] [tag]
git checkout -b [branch] [tag]
---后悔药--------
git checkout .
git reset --hard HEAD^
git reset [file]
git reset --hard
git revert [commit]
git stash
git stash pop
---文件信息-----
git log
git log --stat
git log -S [keywords]
git log -p [file]
git log -5 --pretty --oneline
git log -5 --pretty --online
git blame [file]
git diff
git diff --cached [file]
git diff HEAD
git status
git reflog