常用

git clone

git checkout

git status -s

git diff

git log

git reset HEAD^

git add

git commit

git push

git help 和 git stash或xxx命令 --help

(1)

PS D:\> git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>][--exec-path[=<path>]] [--html-path] [--man-path] [-[-p | --paginate | -P | --no-pager] [--no-replace-ob[--git-dir=<path>] [--work-tree=<path>] [--namespace<command> [<args>]These are common Git commands used in various situations:start a working area (see also: git help tutorial)clone      Clone a repository into a new directoryinit       Create an empty Git repository or reinitialize anwork on the current change (see also: git help everyday)add        Add file contents to the indexmv         Move or rename a file, a directory, or a symlinkreset      Reset current HEAD to the specified staterm         Remove files from the working tree and from the iexamine the history and state (see also: git help revisions)bisect     Use binary search to find the commit that introdugrep       Print lines matching a patternlog        Show commit logsshow       Show various types of objectsstatus     Show the working tree statusgrow, mark and tweak your common historybranch     List, create, or delete branchescheckout    Switch branches or restore working tree filescommit     Record changes to the repositorydiff       Show changes between commits, commit and workingmerge      Join two or more development histories togetherrebase     Reapply commits on top of another base tiptag        Create, list, delete or verify a tag object signecollaborate (see also: git help workflows)fetch      Download objects and refs from another repositorypull       Fetch from and integrate with another repositorypush       Update remote refs along with associated objects

(2)

cmd:git stash --help 来查看help:

浏览器显示 file:///D:/Git/mingw64/share/doc/git-doc/git-stash.html

查看仓库地址:git remote -v

git fetch 和git pull 的差别

1、git fetch 相当于是从远程获取最新到本地,不会自动merge,如下指令:

 git fetch orgin master //将远程仓库的master分支下载到本地当前branch中git log -p master  ..origin/master //比较本地的master分支和origin/master分支的差别git merge origin/master //进行合并

也可以用以下指令:

git fetch origin master:tmp //从远程仓库master分支获取最新,在本地建立tmp分支git diff tmp //將當前分支和tmp進行對比git merge tmp //合并tmp分支到当前分支

2. git pull:相当于是从远程获取最新版本并merge到本地

git pull origin master

git pull 相当于从远程获取最新版本并merge到本地

在实际使用中,git fetch更安全一些

git stash/ git stash pop

将改了的内容先放到内存,以免pull的时候冲突

other stash cmd:

    1) stash列表 git stash list查看

    2) 删除stash git stash drop <stash@{id}> 如果不加stash编号,默认的就是删除最新的,也就是编号为0的那个,加编号就是删除指定编号的stash。git stash clear 是清除所有stash

    3)更多:file:///D:/Git/mingw64/share/doc/git-doc/git-stash.html 如下:

    git stash list [<options>]git stash show [<options>] [<stash>]git stash drop [-q|--quiet] [<stash>]git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]git stash branch <branchname> [<stash>]git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet][-u|--include-untracked] [-a|--all] [-m|--message <message>][--] [<pathspec>…​]]git stash cleargit stash create [<message>]git stash store [-m|--message <message>] [-q|--quiet] <commit>

git reset HEAD

(详见git回退:https://blog.csdn.net/chushoufengli/article/details/101683839

拉取最近一次提交到版本库的文件到暂存区 

在Git中,用HEAD表示当前版本,上一个版本就是HEAD^,上上一个版本就是HEAD^^,当然往上100个版本写100个^比较容易数不过来,所以写成HEAD~100。

拉取项目覆盖本地

(详见git回退:https://blog.csdn.net/chushoufengli/article/details/101683839

git fetch --all

git reset --hard origin/master

git pull

撤销commit

git add .

git commit -m ""

之后想撤回commit:git reset --soft HEAD^

分支管理:


1. 创建分支:git branch (branchname)
//没有参数时,git branch 会列出你在本地的分支。2. 分支信息:git branch
$ git branch
* master  //*当前分支newtest3. 切换分支:git checkout (branchname)
git checkout -b (branchname) 命令来创建新分支并立即切换到该分支下git clone下来的有全部的分支,显示的分支只是默认显示分支4. 删除分支:git branch -d (branchname)5. 合并分支:git merge  //将任何分支合并到当前分支中去
$ git branch
* masternewtest
$ git merge newtest5-1. 合并产生冲突,需要手动去修改
$ git merge change_site
Auto-merging runoob.php
CONFLICT (content): Merge conflict in runoob.php
Automatic merge failed; fix conflicts and then commit the result.5-2. 用 git add 要告诉 Git 文件冲突已经解决
$ git add runoob.php5-3. 提交:
$ git commit5-4. 注:没有冲突的合并,git status是没有东西的,直接push即可

两种方式来合并 详细https://blog.csdn.net/chushoufengli/article/details/102524506

合并到master:切换到masterpull mastergit mergesolve conflitgit add .git commitgit push

 feat分支和dev分支有冲突,因为dev上有改动,在feat分支上git pull origin dev,本地解决冲突,然后提交

git checkout 和 git checkout -b

当使用 git checkout -b sprint-2 切换到 sprint-2分支时 报 pathspec 'sprint-2' did not match any file(s) known to git 错误

使用 git checkout -b sprint-2 创建并切换 sprint-2 分支

使用 git pull origin sprint-2 从远程的 sprint-2 分支pull到本地的 sprint-2 (因为本地和远程不是一个源,所以pull需要加上origin sprint-2)

同理 git push --set-upstream origin sprint-2

使用git在本地新建一个分支后,需要做远程分支关联。如果没有关联,git会在下面的操作中提示你显示的添加关联。

关联目的是在执行git pull, git push操作时就不需要指定对应的远程分支,你只要没有显示指定,git pull的时候,就会提示你。

解决方法就是按照提示添加:

git branch --set-upstream-to=origin/remote_branch  your_branch

其中,origin/remote_branch是你本地分支对应的远程分支;your_branch是你当前的本地分支。

git checkout -b dev 与 git checkout -b dev master 有什么区别?

前者:创建了一个名称为dev的分支并切换到dev分支上去
后者:从master分支分化一个新分支名为dev,并切换到dev分支上去

git merge --no-ff

git merge --no-ff "feat-kuaidi100"

从合并后的代码来看,结果其实是一样的,区别就在于 --no-ff 会让 Git 生成一个新的提交对象。为什么要这样?

通常我们把 master 作为主分支,上面存放的都是比较稳定的代码,提交频率也很低,
而 feature 是用来开发特性的,上面会存在许多零碎的提交,
快进式合并会把 feature 的提交历史混入到 master 中,搅乱 master 的提交历史。
所以如果你根本不在意提交历史,也不爱管 master 干不干净,那么 --no-ff 其实没什么用。
不过,如果某一次 master 出现了问题,你需要回退到上个版本的时候,
比如上例,你就会发现退一个版本到了 B,而不是想要的 F,因为 feature 的历史合并进了 master 里。

(https://blog.csdn.net/zombres/article/details/82179122)

git remote set-url

git remote set-url origin http://gitlab.haibaodianjing.com/maoqiudao/server.git

取消add commit

取消add git reset HEAD
取消commit git reset HEAD^

检出某次提交(远程/本地)
git reflog
git checkout 5a009c7

git reset (–mixed) HEAD~1(待定)
回退一个版本,且会将暂存区的内容和本地已提交的内容全部恢复到未暂存的状态,不影响原来本地文件(未提交的也
不受影响)
git reset –soft HEAD~1
回退一个版本,不清空暂存区,将已提交的内容恢复到暂存区,不影响原来本地的文件(未提交的也不受影响)
git reset –hard HEAD~1
回退一个版本,清空暂存区,将已提交的内容的版本恢复到本地,本地的文件也将被恢复的版本替换

git cherry-pick

可以理解为”挑拣”提交,它会获取某一个分支的单笔提交,并作为一个新的提交引入到你当前分支上。 
当我们需要在本地合入其他分支的提交时,如果我们不想对整个分支进行合并,而是只想将某一次提交合入到本地当前分支上,那么就要使用git cherry-pick了。
(https://blog.csdn.net/fightfightfight/article/details/81039050)

git log

git log 命令可以显示所有提交过的版本信息
git reflog 可以查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作)

+ git checkout

.gitIngore内容:

# Created by .ignore support plugin (hsz.mobi)
.idea/
go.sum

git checkout 788258e49531eb24bfd347a600d69a16f966c495

删除git仓库

即删除仓库文件夹下隐藏的 .git 文件夹
$ ls -a
$ rm -rf .git
$ ls -a

查看某文件的历史提交

git log -p user.go
-p 选项展开显示每次提交的内容差异
git文档(https://git-scm.com/book/zh/v1/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2)

git blame 追溯一个指定文件的历史修改记录

显示格式:commit ID  (代码提交作者  提交时间  代码位于文件中的行数)  实际代码

fork

(查看本地仓库 git remote -v  (remote:远程

本地添加远程库:git remote add wxx https://git.xxx.net/xx.wang/xxx

指定库和分支push:git push wxx b1

git rm 、git rm --cached的区别

【git rm】
当我们需要删除暂存区或分支上的文件, 同时工作区也不需要这个文件了, 可以使用git rm
git rm file = rm file+ git add file  (rm file删除本地文件,git add file 提交删除的步骤同步到git仓库

【git rm --cached file】
当我们需要删除暂存区或分支上的文件, 但本地又需要使用, 只是不希望这个文件被版本控制, 可以使用 git rm --cached
git rm --cached 会从index里面删除该文件,下次commit的时候会修改git仓库,但是本地的文件还是保留

【显示Untracked files】
Untrack and stop tracking files in git
有一些文件我们不想提交到git上去了,但是又被检测到有变化,显示Untracked files,我们可以采用
git rm --cached file来停止跟踪这些文件

git切换分支报错

error: pathspec '分支名' did not match any file(s) known to git.

执行一下:git fetch

更多详细:

基本操作:   https://www.runoob.com/git/git-basic-operations.html

分支管理:  https://www.runoob.com/git/git-branch.html

git 详细文档:https://git-scm.com/book/zh/v2

【备份】git命令行相关推荐

  1. 如何用git命令行上传本地代码到github

    如何用git命令行上传本地代码到github 2016年09月19日 16:10:36 阅读数:9337 注意:安装的前提条件是配置好git的相关环境或者安装好git.exe,此处不再重点提及 上传的 ...

  2. git命令行完全解读

    BY 张建成(prettyEcho@github) 除非另行注明,页面上所有内容采用知识共享-署名(CC BY 2.5 AU)协议共享 原文地址deep.js , 欢迎 评论 和 star ?? 欢迎 ...

  3. 关于使用 git 命令行来和“码云”账号上的项目互通过程的基础步骤

    前提:已经有码云账号,电脑已经安装了git工具. (1)在码云账号上登陆自己的账号,创建一个新的项目. (2)在自己的本地磁盘下随便创建一个文件夹(例如起名为:mayun),用来存放从码云上拉下来的项 ...

  4. 【重要】使用Git命令行上传到GitHub上

    [本人GitHub账号:] 用户名:chenhongshuang 密码:shuangshuang6300 邮箱:2452420371@qq.com 进入GitHub账号后 1·新建项目文件名称例dem ...

  5. 如何使用git命令行上传项目到github

    参考文献: 如何使用git命令行上传项目到github 感谢楼主分享!

  6. Git命令行介绍和使用说明(持续更新)

    Git命令行介绍和使用说明(持续更新) Git命令行介绍和使用说明(持续更新) 文档名称 Git命令行介绍和使用说明会 创建时间 2012/8/23 修改时间 2012/8/23 创建人 Baifx ...

  7. linux tig不支持中文,tig — 让 git 命令行可视化

    tig 是一款优化 git 命令行的工具,使 git 命令行更加的便捷人性化 .如果用习惯了,会上瘾. image 基础 安装 在 Mac 上最简单的方式是使用 Homebrew: brew inst ...

  8. gitBash快速清屏,git命令行操作,快速清屏,清屏

    ## ** gitBash快速清屏,git命令行操作,快速清屏,清屏 ** 快捷键 点赞去啊!!!!!!!!!!!!!

  9. zbb20190109 git命令行解决冲突文件步骤

    git命令行解决冲突文件步骤 方法一(推荐使用): git pull 出现冲突后丢弃本地冲突文件修改,采用远程文件覆盖本地文件 git checkout  [文件路径] 例:git checkout  ...

  10. 使用Git命令行推送代码到远程仓库,阿里云效Codeup代码管理平台

    项目提交暂存.提交本地仓库.拉取.推送: [本步骤是新项目流程]请自行根据自有项目分辨是否需要跳过前两步. 右键点击项目根文件夹,选中Git Bash Here,打开命令行. (1)初始化项目命令: ...

最新文章

  1. 进阶篇第十一期:高德地图的使用
  2. 【感悟随笔】没能变强是因为你太贪图舒服了
  3. 如何使用jquery_好程序员web前端学习路线分享jQuery学习技巧
  4. 树莓派4B Raspbian-buster 更换源
  5. pandas添加、修改dataframe中index的列名
  6. 对xml文件的增删改查及读写
  7. 设计模式之十五:訪问者模式(Visitor Pattern)
  8. ARX帮助文档:数据库对象
  9. 测试项目的makefile
  10. CoolFire系列讲座 第5讲:善用你所得到的任何资讯 (Exm: HOSTS 档)
  11. Linux:struct dirent
  12. HYSPLIT简明教程
  13. 全国各地电信DNS服务器地址
  14. xdg-open命令
  15. 转载:使用pythonr脚本实现微信公众号音频批量下载
  16. 启英泰伦三代离线语音AI芯片及AIoT芯片介绍
  17. Oracle查看ogg延时,OGG复制进程延迟不断增长
  18. PHP拼团人数不能超过,怎么解决拼团、抽奖难以凑齐人数这个大问题?
  19. html 的id指什么,appid是什么?
  20. ping 命令的实现

热门文章

  1. information_schema.columns 学习
  2. “万年老大难” - 沟通与协调
  3. 分类:支持向量机(四)——非线性支持向量机
  4. 使用 EPUB 制作数字图书 基于 XML 的开放式 eBook 格式
  5. 入门PerfDog性能测试
  6. 洛谷 P2708 硬币翻转 题解
  7. 微信小游戏 缓存目录
  8. 12-监听器实现统计网站当前在线人数
  9. Nginx系列1: 正向代理和反向代理、Nginx工作原理、Nginx常用命令和升级、搭建Nginx负载均衡
  10. mysql存储过程之循环(WHILE,REPEAT和LOOP)