常规操作
查看状态
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
$ 查看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
添加变更到上一次的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
- reset ⚠️ Resetting Is Dangerous ⚠️
$ git reset --hard HEAD^
$ git reset
取消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, theheading-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 ""
# sets up Git with your email
git config --global user.email ""
# 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"