• git常用命令


    Git global setup

    git config --global user.name "myName"
    git config --global user.email "myEmail"
    

    Create a new repository

    git clone git@git.*.com:*/test.git
    cd test
    touch README.md
    git add README.md
    git commit -m "add README"
    git push -u origin master
    

    Existing folder or Git repository

    cd existing_folder
    git init
    git remote add origin git@git.*.com:*/test.git
    git add .
    git commit
    git push -u origin master
    

    git常用命令汇总

    命令 作用 备注
    git init
    git clone [url]
    git branch branch-name 创建分支
    git checkout branch-name 切换分支 如果本地 branch-name 分支不存在,会自动创建基于远程 branch-name 的分支并切换
    git checkout -b branch-name 创建+切换分支,基于本地当前分支
    git checkout -b branch-name origin/remote-name 创建+切换分支,基于远程库的 remote-name 分支
    git checkout –b branch-name commitID 创建+切换分支,基于某次提交
    git branch 列出本地分支 q 退出
    git branch –m old new 重命名 old 分支
    git status 查看状态
    git diff 尚未缓存的改动
    git diff --cached 或 git diff --staged 查看已缓存的改动
    git diff HEAD 查看已缓存的与未缓存的所有改动
    git diff --stat 显示摘要而非整个 diff
    git add -u 提交被修改和被删除文件,不包括新文件 仅监控 tracked file
    git add . 提交新文件和被修改文件,不包括被删除文件
    git add -A 提交所有变化
    git commit –m "commint-message" 提交到版本库
    git branch –d branch-name 删除分支 需要切换到其它分支之后删除
    git branch –D branch-name 强制删除分支
    git pull origin branch-name 获取远程 branch-name 合并到当前本地分支
    git push origin source:target 推入远程库 git push origin branch-name 会推入到远程 branch-name 分支
    git push origin :branch-name 删除远程 branch-name 分支 把空的推入
    git reset --hard/soft/mixed commitID/HEAD^^/HEAD~2 版本回退到某次提交(hard 参数可变) hard: 撤销工作区、暂存区、版本库的改变;mixed:撤销暂存区,版本库的改变;soft:只撤销版本库的改变
    git revert commitID/HEAD^^/HEAD~2 提交一个新的版本,将需要 revert 的版本的内容再反向修改回去
    git rm -r --cached . 清空暂存区 .gitignore 只能忽略 untracked 文件
    git config diff.nodiff.command /usr/bin/true git diff 时忽略某个文件 前提是在项目根目录下创建 .gitattributes,添加 dist/**/* diff=nodiff

    .gitignore文件规则

    举例 作用
    *.a 忽略所有 .a 结尾的文件
    !lib.a 但 lib.a 除外
    /TODO 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
    build/ 忽略 build/ 目录下的所有文件
    doc/*.txt 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

    git stash用法

    命令 作用 备注
    git stash 保存所有未提交的修改(包括暂存的和跟踪未暂存的,不包括未跟踪和被忽略的) stash 是本地的,不会通过 git push 命令上传到 git server 上。
    git stash -u 可以保存未跟踪的
    git stash -a 可以同时保存未跟踪和被忽略的
    git stash save "stash-message" 添加备注 使用 git stash save 取代 git stash 命令
    git stash list 查看现有 stash
    git stash pop 重新应用缓存的最近的 stash 将缓存堆栈中的第一个 stash 删除,并将对应修改应用到当前的工作目录下
    git stash apply 重新应用缓存的最近的 stash 应用但不删除。git stash apply stash@{0} 会应用指定的 stash
    git stash show 显示最近 stash 的 diff(摘要) git stash show stash@{0} 会显示指定 stash 的 diff(摘要)
    git stash show -p 显示最近 stash 的 diff(完整)
    git stash drop 移除最近的 stash git stash drop stash@{0} 会移除指定的 stash
    git stash clear 删除所有缓存的 stash
    git stash branch branch-name 基于保存工作时的提交创建并切换新分支,重新应用工作。如果成功,将会丢弃缓存 git stash branch branch-name stash@{0} 会基于指定的 stash

    git merge 用法

    待更新

    git rebase 用法

    待更新

  • 相关阅读:
    Java中last_insert_id的使用
    Java上传视频
    Java创建Excel-DEMO
    导出excel表格
    Java导入excel并保存到数据库
    Java基础13一异常
    Java基础12一IO流
    腾讯云-等保要求
    云安全等保项目服务内容及云安全产品清单-(腾讯云部分)
    《网络风险及网络安全》培训总结
  • 原文地址:https://www.cnblogs.com/flying-script/p/14867152.html
Copyright © 2020-2023  润新知