git 一些常用命令【随用随记】

March 9th 切换到指定提交id的分支

git checkout 提交id

nov 16th

从想创建一个远程仓库说起

常用的做法是打开sourceTree --> 新建url --> 从URL克隆 --> 然后...
好吧扯远了,这次用命令行创建一个远端仓库

  • 准备一个远端的git 链接,比如 https://github.com/xxxx/xxxx.git
  • 欲创建远端,先创建本地仓库
    • cd 到你想要的路径,然后:
    • git init
    • 一般命令行会出现
      Initialized empty Git repository in 你的路径/.git/
    • ls -al
      会出现 文件路径表,唯一舒心的就是.git文件夹
  • 添加远端仓库
    • git remote add 远端名字(即远端服务器的别名,pull代码等的时候会用到) 远端git链接
    • git remote -v 查看一下远端的仓库,会列出远端的权限
      remote https://github.com/xqqq0/pyqueryPrac.git (fetch)
      remote https://github.com/xqqq0/pyqueryPrac.git (push)
    • 查看远端分支【假定远端有多个分支,我们选择其中一个checkout到本地】
      git branch -a
  • pull 远端代码到本地
    git pull 刚才定义的远端服务器别名
  • 将远端分支拉取到本地
    • git checkout -b 本地分支名 origin/远程分支名
  • pull 代码
    • git pull

nov 14th

提交

  • 将文件提交至暂存区
    • git add 文件名
  • 将所有修改的文件提交
    • git add ./
  • 本地提交
    • git commit -m"提交log"
  • 推送到远程
    • git push

打tag

看这里

log 相关

  • 查看log
    • git log
  • 查看文件的修改内容
    • git log -p 文件名

分支相关

  • 查看
    • 远端:git branch -a
    • 本地:git branch
  • 创建本地分支
    git branch 分支名
  • 推送本地分支到远端
    git push origin 本地分支名字
  • 将远程git仓库里的指定分支拉取到本地(在本地分支不存在的情况下)
    • git checkout -b 本地分支名 origin/远程分支名
  • 切换分支
    • git checkout 分支名
  • 创建分支并切换
    • git checkout -b 分支名
  • 删除本地分支
    • git branch -D loacal0

你可能感兴趣的:(git 一些常用命令【随用随记】)