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

    摘要

    经常记不住git的常用命令,做个备注

    参考: https://backlogtool.com/git-tutorial/cn/contents/

    命令

    查看分支

    git branch -a

    创建分支

    git checkout -b

    合并分支

    git merge 分支名

    拉分支

    git checkout 分支名

    重命名分支

    git branch -m devel 分支名

    删除分支

    git branch -d 分支名
    git push origin --delete
    git push origin :分支名

    推送tags

    git push --tags

    获取tag

    git fetch origin tag

    删除tag

    git push origin --delete tag
    git tag -d
    git push origin :refs/tags/

    查看日志

    git log

    文件

    git checkout 文件

    撤销提交

    git revert HEAD 撤销前一次 commit
    git revert HEAD^ 撤销前前一次 commit
    git revert commit (比如:fa042ce57ebbe5bb9c8db709f719cec2c58ee7ff)撤销指定的版本,撤销也会作为一次提交进行保存。

    删除提交

    git reset HEAD ..

    恢复到某次commit

    git reset --hard <commit_id>
    git push origin HEAD --force

    远程数据库

    pull

    拉取远程代码并合并, 等于 fetch + merge

    fetch

    拉取远程代码到 FETCH_HEAD

    push

    提交代码到远程,建议提交之前 pull 合并最新代码, 避免push失败
    强制覆盖分支
    git push origin 源分支:目标分支 -f

    与fork的分支合并

    git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
    git fetch upstream
    git merge upstream/master

    设置账户信息

    git config --global user.email "email@example.com" 全局
    git config --global user.email 查看全局账户信息
    git config user.email "email@example.com" 当前仓库
    git config user.email 查看当前仓库账户信息
    https://help.github.com/articles/setting-your-commit-email-address-in-git/

    更新commit author信息

    git commit --amend --reset-author 把最近一次commit重置为当前用户

    分支分类

    遇到 submodule 无法追踪的 变更

    取消变更
    git update-index --skip-worktree path

  • 相关阅读:
    commando VM安装
    Pocscan搭建详解
    Windows-RW-LinuxFS
    Festival
    ffmpeg-metadata
    FFmpeg-Screen-Recording
    ffmpeg-map
    ffmpeg-utils
    Linux-Fcitx5
    ffmpeg-volumedetect
  • 原文地址:https://www.cnblogs.com/huxiaoyun90/p/7543066.html
Copyright © 2011-2022 走看看