美文网首页
git 常用操作 / 配置

git 常用操作 / 配置

作者: Squall_峰 | 来源:发表于2018-11-11 16:44 被阅读0次

常规操作

查看状态

git status

branch 操作

$ git branch #列出所有的branch
$ git branch squall #新建一个branch
$ git checkout squall #切换到squall分支
$ git branch -d squall #删除branch
$ git log --oneline --decorate --graph --all #查看所有branch状态

merge 合并

$ git merge <other-branch>

$ 查看log日志

$ git log
$ git log --oneline #单行

github:

create a new repository on the command line

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/dyfsquall/zhihu_scrapy.git
git push -u origin master

…or push an existing repository from the command line

git remote add origin https://github.com/dyfsquall/zhihu_scrapy.git
git push -u origin master

重命名一个文件

git mv oldFileName newFileName
git commit oldFileName -m"say something"
git commit newFileName -m"say something"
git pull
git push -u origin master

版本迭代

# create a tag
$ git tag -a v1.0 
# 查看版本
$ git tag
$ git log
# delete a tag
$ git tag -d v1.0

取消add

git rm --cached <file>

添加变更到上一次的commit

  • edit the file(s)
  • save the file(s)
  • stage the file(s)
  • and run git commit --amend
git commit --amend

git丢弃本地修改的所有文件(新增、删除、修改)

git checkout . #本地所有修改的。没有的提交的,都返回到原来的状态
git stash #把所有没有提交的修改暂存到stash里面。可用git stash pop回复。
git reset --hard HASH #返回到某个节点,不保留修改。
git reset --soft HASH #返回到某个节点。保留修改

git clean -df #返回到某个节点
git clean 参数
    -n 显示 将要 删除的 文件 和  目录
    -f 删除 文件
    -df 删除 文件 和 目录

# 退回到修改前的状态
git checkout . && git clean -xdf

回退commit

Reverting creates a new commit that reverts or undos a previous commit. Resetting, on the other hand, erases commits!

  • revert
$ git revert <SHA-of-commit-to-revert>
  • reset ⚠️ Resetting Is Dangerous ⚠️
$ git reset --hard HEAD^
$ git reset <reference-to-commit>

取消git初始化

rm -rf .git

merge合并冲突

Merge Conflict Indicators Explanation

$ git merge heading-update 
Auto-merging index.html
CONFLICT (content): Merge conflict in index.html
Automatic merge failed; fix conflicts and then commit the result.

The editor has the following merge conflict indicators:

  • <<<<<<< HEAD everything below this line (until the next indicator) shows you what's on the current branch
  • ||||||| merged common ancestors everything below this line (until the next indicator) shows you what the original lines were
  • ======= is the end of the original lines, everything that follows (until the next indicator) is what's on the branch that's being merged in
  • >>>>>>> heading-update is the ending indicator of what's on the branch that's being merged in (in this case, the heading-update branch)

在.gitignore 中添加如下设置

*.txt
.vscode/
.idea/
migrations/
*.pyc
*.toc
*.seg
whoosh_index/
*.pem
node_modules/
.tmp
.sass-cache
*.mp3
*.mp4

账号配置

$vi ~/.gitconfig
# sets up Git with your name
git config --global user.name "<Your-Full-Name>"

# sets up Git with your email
git config --global user.email "<your-email-address>"

# makes sure that Git output is colored
git config --global color.ui auto

# displays the original state in a conflict
git config --global merge.conflictstyle diff3

git config --list

VSCode Setup

git config --global core.editor "code --wait"

相关文章

  • git常用命令

    初始配置 常用命令 git操作原则 vim基本操作

  • git常用操作

    git缩写配置: 在.gitconfig文件中添加: [alias] git常用操作: git clone 克隆一...

  • git常用操作 🎀

    git常用操作 ? 基本知识 查看git信息 修改git配置 提交类操作 分支类操作 创建分支 查看分支 修改分支...

  • git常用操作记录

    常用配置操作 配置用户变量 git config --global user.name "your name"gi...

  • git 常用操作命令

    常用操作 查看git 配置信息git config --list配置个人的用户名名称和电子邮件地址当前仓库git ...

  • Git常用命令

    配置操作 本次操作 分支操作 变更历史 标签操作 远程交互 来源:常用的 Git 操作[https://www.t...

  • git常用操作

    git常用操作 第一次连接远程仓库的配置 配置user.name 和user.email git config -...

  • git 常用操作 / 配置

    常规操作 查看状态 branch 操作 merge 合并 $ 查看log日志 github: create a n...

  • Git操作记录

    本文目录 一台电脑配置多个git账号 git常用的操作命令 使用git命令合并多条commit记录 使用git命令...

  • [ Git ] 快速参考

    配置 常用的用户信息配置 常用的别名配置 git rm 的用法 git reset 的用法 git stash 的...

网友评论

      本文标题:git 常用操作 / 配置

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