GIT

作者: 终极蚂蚁 | 来源:发表于2019-03-22 11:31 被阅读0次

git

  • git命令:

      查看分支列表: `git branch -a`
      查看分支列表: `git branch --list`
      查看分支:`git branch` 同上
      创建分支:`git branch <name>`
      切换分支:`git checkout <name>`
      创建+切换分支:`git checkout -b <name>`
      合并某分支到当前分支:`git merge <name>`
      删除分支:`git branch -d <name>`
      默认分支管理,需要去对应的托管网站,登录账号,然后进行设置。
    
  • 强行覆盖

开发时,对于本地的项目中修改不做保存操作(或代码改崩),可以用到Git pull的强制覆盖,具体代码如下:

git fetch --all
git reset --hard origin/master
git pull //可以省略

git fetch 指令是下载远程仓库最新内容,不做合并
git reset 指令把HEAD指向master最新版本
  • 清缓存
    git .ignore 清除缓存方法

    D:\workspace\mark_doc>git rm -r --cached .
    rm '.gitignore'
    rm 'README.md'
    rm 'markdown/database/存储过程.md'
    
    Warning: Your console font probably doesn't support Unicode. If you experience strange characters in the ou
    tput, consider switching to a TrueType font such as Consolas!
    
    D:\workspace\mark_doc>git add .
    warning: LF will be replaced by CRLF in .idea/inspectionProfiles/Project_Default.xml.
    The file will have its original line endings in your working directory.
    warning: LF will be replaced by CRLF in .idea/mark_doc.iml.
    The file will have its original line endings in your working directory.
    warning: LF will be replaced by CRLF in .idea/modules.xml.
    The file will have its original line endings in your working directory.
    warning: LF will be replaced by CRLF in .idea/vcs.xml.
    The file will have its original line endings in your working directory.
    warning: LF will be replaced by CRLF in .idea/workspace.xml.
    The file will have its original line endings in your working directory.
    
    D:\workspace\mark_doc>
    
    git rm -r --cached .
    git add .
    git commit -m  .gitignore
    
      - mkdir [文件夹名]
      - git init
      - git init [文件夹名]
      - git clone [gitUrl]
      - git clone [gitUrl] [本地地址及名称]
      - git status
      - git status -s
          -s,获得简短的结果输出
      - git diff
      - git diff --cached
      - git diff HEAD
      - git diff --stat
      - git add .
      - git add [文件名]
    
      - git commit
      - git reset HEAD
          用于取消已缓存的内容。(已经被add,可以取出commit行列)
          执行 git reset HEAD 以取消之前 git add 添加,但不希望包含在下一提交快照中的缓存。
    
      - git rm [文件名]
          直接删除文件
      - git rm --cache [文件名]
      - git rm -f [文件名]
      - git rm -r *
          可以递归删除,即如果后面跟的是一个目录做为参数,则会递归删除整个目录中的所有子目录和文件
      - git mv del.md test.md 命令用于移动或重命名一个文件、目录、软连接。(将del.md重命名为test.md)
    
      git 分支
      - git branch [branchName] 创建分支命令
      - git checkout [branchName] 切换分支命令
      - git merge [branchName] 将branchName分支合并到当前分支
    
      - git branch 列出本地分支列表
      - git branch --list 同上
      - git
      - ls 列出文件列表
      - ll 列出文件列表(包含权限)
      - git checkout -b [newBranchName] 创建newBranchName并切换到新分支
      - git branch -a 查看所有分支列表
      - git branch -d [branchName] 删除分支
      - git log 查看提交历史
      - git log --oneline 查看历史记录简介版本
      - git log --oneline --graph 查看log树
      - git log --reverse --oneline
      也可以用 '--reverse'参数来逆向显示所有日志。
    
      git log --author=guofei --oneline -5
      只查看guofei提交的日志,5行
      --no-merges 选项以隐藏合并提交
      - vim [文件名] 编辑某文件
      - git tag -a v1.0 给当前提交添加标签
      - git tag -a v0.9 [da6835e] 给某个提交插入标签
      - git tag 查看tag
      - git tag -a test
      - git tag -d v1.0 删除标签
      - git show v1.0 查看v1.0提交的内容
    

    git-菜鸟教程

git 创建git仓库到指定目录

mayn@DESKTOP-L7PRRDN MINGW64 ~/Desktop/test_git
$ git init repo
Initialized empty Git repository in C:/Users/mayn/Desktop/test_git/repo/.git/

mayn@DESKTOP-L7PRRDN MINGW64 ~/Desktop/test_git
$

git clone 代码到当前目录以... 命名文件夹

mayn@DESKTOP-L7PRRDN MINGW64 ~/Desktop/test_git
$ git clone https://gitee.com/guo_fei/gf_learn.git learn
Cloning into 'learn'...
remote: Enumerating objects: 837, done.
remote: Counting objects: 100% (837/837), done.
remote: Compressing objects: 100% (676/676), done.
remote: Total 837 (delta 337), reused 119 (delta 56)0 KiB/s
Receiving objects: 100% (837/837), 26.52 MiB | 315.00 KiB/s, done.
Resolving deltas: 100% (337/337), done.

mayn@DESKTOP-L7PRRDN MINGW64 ~/Desktop/test_git
$

查看git状态

mayn@DESKTOP-L7PRRDN MINGW64 ~/Desktop/test_git/learn (test)
$ git status
On branch test
Your branch is ahead of 'origin/test' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

相关文章

网友评论

      本文标题:GIT

      本文链接:https://www.haomeiwen.com/subject/lojlvqtx.html