dev-tools-git

版本控制工具

符号笔记

命令

结合IDE 一起用;常用常新
Git | IntelliJ IDEA Documentation (jetbrains.com)

git help [todo]
Git - Getting Help (git-scm.com)
最全的git命令(详细)和对常见git操作流程讲解 - 掘金 (juejin.cn)

分支 本地 远程
代码 工作区 暂存区 版本库 远程仓库
一个分支上的代码 写代码 代码 加入到 Git管理 代码提交形成记录 代码记录同步到共享代码库

## 工作区-> 暂存区
git add *

## 工作区<- 暂存区
暂存区
git stash save  (隐藏暂存代码但不删除)
<- git stash list  (暂存列表)
<- git stash apply  (取消最近一次暂存)
<- git stash apply stash@{n}    `n ∈[0,n) (取消 第n+1次 暂存)

## 暂存区
分类:Move to another changeList -> 隐藏应用到所有版本: Sheleve changes / VS stash,stash 一次暂存所有文件;Sheleve 一次暂存部分文件

## 暂存区->版本库
git commit -m ['commit_message']  (提交到版本库)

## 暂存区->版本库 取消
git commit --amend -m  ['commit_message']  (修改上次提交到版本库,push 前可操作)

## 暂存区<-版本库
git reset --soft HEAD~n  n ∈[1,n] (回退到前n次提交)

idea 可视化中 是 git undo commit

## 版本库
合并提交记录:rebase from hear -> move -> fix-up() -> squash -> 


## 版本库->远程仓库
git push origin master (first push)  (提交到远程仓库)

<-git push (not first push) 

## 版本库->远程仓库 取消
git reset --soft HEAD~n  n ∈[1,n] (回退到前n次提交) git push force (取消提交到远程仓库)

<-git revert --soft HEAD~n  n ∈[1,n] (回退到前n次提交 形成新提交) git push (提交到远程仓库)

<- git reset --hard HEAD@{n} n ∈[1,n] (取消 前n次的回退)

## 版本库<-远程仓库
git clone  (first full get)

git pull  (not first full get)

git merge (合并冲突代码)

## 本地分支->远程分支
git checkout -b [branch_name] (新建分支 并切到新分支)

git push origin [branch_name]   (提交 本地分支 到  远程分支)

## 本地分支
git cherry-pick [commit]   (选择一个 提交记录 合并 到 当前分支)

git branch -d [branch-name]  (删除本地分支)

git branch -dr [remote/branch]  (删除远程分支)

## 本地分支<-远程分支
git fetch (拉分支)

.gitignore

忽略特定文件,支持通配符

*.a             表示忽略所有 .a 结尾的文件
!lib.a          表示lib.a除外
 
/TODO           表示仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/          表示忽略 build/目录下的所有文件,过滤整个build文件夹;
doc/*.txt       表示会忽略doc/notes.txt但不包括 doc/server/arch.txt
 
bin/:           表示忽略当前路径下的bin文件夹,该文件夹下的所有内容都会被忽略,不忽略 bin 文件
/bin:           表示忽略根目录下的bin文件
/*.c:           表示忽略cat.c,不忽略 build/cat.c
debug/*.obj:    表示忽略debug/io.obj,不忽略 debug/common/io.obj和tools/debug/io.obj
/foo:         表示忽略/foo,a/foo,a/b/foo等
a//b:         表示忽略a/b, a/x/b,a/x/y/b等
!/bin/run.sh    表示不忽略bin目录下的run.sh文件
*.log:          表示忽略所有 .log 文件
config.php:     表示忽略当前路径的 config.php 文件
 
/mtk/           表示过滤整个文件夹
*.zip           表示过滤所有.zip文件
/mtk/do.c       表示过滤某个具体文件

config

  1. To ignore CRLF vs LF, set core.autocrlf=true in the .git/config file:

    • true: on checkout, convert LF to CRLF; on commit, keep as LF. This fits Windows.
    • input: on checkout, keep as LF; on commit, keep as LF. This fits Unix or Linux.
  2. If the file name should not ignore case, set core.ignorecase=false in the .git/config file; then use lowercase to fit URLs.

多账号