zoukankan      html  css  js  c++  java
  • git 我的常用命令

    git config --list  查看配置

    git config --global user.name zhiqsyr  配置用户名:zhiqsyr

    git config --global user.email zhiqsyr@163.com  配置邮箱

    git config --global credential.helper cache  设置记住密码(默认15分钟)

    git config --global credential.helper  'cache --timeout=3600'  设置记住密码一个小时

    git config --global credential.helper store  设置长期存储密码(在下一次拉远程代码输完帐号后生效)

    git remote add origin http://name:password@gitee.com/name/project.git  增加远程地址,带上密码

    git config --global --unset core.quoteapth  删除配置 core.quoteapth 

    git init  在当前目录建立 git 管理

    git clone -b standalone http://gitee.com/name/project.git apache-tomcat-basecenter  克隆 standalone 分支到 apache-tomcat-basecenter 文件夹下

    git status  查看工作区还没 add 的改动文件

    git diff  查看工作区还没 add 的改动文件具体详情

    git diff --cached  查看已 add 还没 commit 文件

    git diff HEAD  git diff 、git diff --cached 两条合并

    git add <file>  将指定文件添加到索引库,以备 commit

    git add .  将当前路径下所有新增或修改(不包括删除)的文件添加到索引库

    git add -u webapps/WeiKeFileStore/WEB-INF/lib/  将 webapps/WeiKeFileStore/WEB-INF/lib/ 目录下修改或删除的文件添加到暂存区

    git update-index --assume-unchanged <file>  文件已经加入版本管理,再做修改不希望加入提交队列(git ls-files -v | grep '^[[:lower:]]'  查看忽略列表)

    git update-index --no-assume-unchanged <file>  取消上面一条命令,还是加入提交队列

    git reset <file>  将指定文件从索引库移除,commit 时不会提交该 file

    git reset -- .  将当前路径下索引库中所有文件移除

    git reset --hard <commit-hash-id>  回退到 <commit-hash-id> 版本(git push origin HEAD --force  更新远程服务器)

    git reflog  罗列 commit log (包括被删的,然后通过 git reset --hard <commit-hash-id> 找回)

    git checkout <commit-hash-id> <file>  回退文件 <file> 到 <commit-hash-id> 版本

    git rm --cached <file>  删除本地版本库中指定文件

    git rm -r --cached <file>  删除本地版本库中指定文件夹及其子文件,git rm -r -n --cached <file> 查看上述将要删除的文件列表

    git log  查看提交历史(时间倒序)

    git log -n 1 --stat  最近一次提交改动的文件(常用)

    git log -n 1 -p  最近一次提交更改的细节

    git stash  

    git stash pop

    分支

    git branch -a  查看所有分支

    git branch -m standalone master  把名为 standalone 分支改为 master(-m 写成 -M,表示强制修改)

    git branch --set-upstream-to=origin/release  本地当前分支关联远程release分支(本地分支pull、push默认指向origin/release)

    git branch -d test  删除本地 test 分支(需要先切到其他分支)

    git branch -d -r origin/test  删除远程 test 分支;删除后还要推送 git push origin :test

    git checkout -b standalone origin/standalone  拉取远程分支origin/standalone到本地分支standalone(本地分支 standalone 已有,直接 git checkout standalone)

    远程仓库

    git remote -v  查看远程仓库信息(名称、地址)

    git remote add origin https://gitee.com/iclassroom/WeiKe.git  为本地 git 库绑定远程库,并指定别名为 origin(https://gitee.com/iclassroom/WeiKe.git/ 更为精确)

    git push origin <local_branch_name>:<remote_branch_name>  本地分支代码上传到指定远程分支(如果远程分支不存在,则新建)

    git remote rm origin  解除绑定 origin 远程仓库

    git remote set-url origin https://gitee.com/iclassroom/WeiKe.git

    git pull origin master  pull 远程 origin 仓库 master 分支;假如 refusing to merge unrelated histories,命令后加 --allow-unrelated-histories

    合并分支

    git diff master origin/standalone --stat  比较本地 master 与远程 origin/standalone 分支差异(需要本地先 git fetch orgin)

    git rebase origin/standalone  合并远程 origin/standalone 分支代码到当前分支,不会产生交叉(单祖先,推荐)。此时 ours=origin/standalone,theirs=当前分支,原因

      git checkout --theirs <file>  使用当前分支文件

      git checkout --ours <file>  使用远程 origin/standalone 分支文件

    git merge origin/standalone  合并远程 origin/standalone 分支代码到当前分支,会产生交叉(多重祖先,容易产生问题)。此时 ours=当前分支,theirs=origin/standalone

  • 相关阅读:
    spring boot SpringApplication.run 执行过程
    算法 计算四则运算字符串结果
    算法 RingBuffer
    java BigDecimal 四舍五入
    算法 常用函数和近似
    java 多线程执行
    Java 三个线程依次输出ABC
    Java interrupt 中断
    java 垃圾收集器与内存分配策略
    软件项目与软件产品的区别
  • 原文地址:https://www.cnblogs.com/zhiqsyr/p/8259957.html
Copyright © 2011-2022 走看看