GIT功能强大,实在是代码管理不二人选,在此想系统总结下,总之,本专辑是自动驾驶,但更是笔者的心路历程,所以都是围绕自动驾驶这一目标展开,十一长假让我懈怠不少,专注力下降,又遇人生两件大事,不免有些波澜,重听王阳明专辑,以求提高自己修为,不求无敌于外,但求宁静于内。https://www.ximalaya.com/youshengshu/23361523/
1. git安装:sudo apt install git
2. zhs 安装: sudo apt-get install -y zsh
3. 安装Oh my zsh:
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
or sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
or 国内可以用:sh -c "$(wget https://gitee.com/Devkings/oh_my_zsh_install/raw/master/install.sh -O -)"
or 国内可以用:sh -c "$(curl -fsSL https://gitee.com/Devkings/oh_my_zsh_install/raw/master/install.sh)"
主题选择:https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
4. 安装高亮插件:
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc
找到plugins,加上这个插件即可:
5. 历史补全代码插件:
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc
找到plugins,加上这个插件即可:
6. git环境配置:
vi ~/.gitconfig
添加一下缩写:
[alias]
co = checkout
ci = commit
st = status
sh = stash
sa = stash apply
sp = stash pop
ap = add -p
br = branch
cp = checkout -p
cv = commit -v
dc = diff --cached
d = diff
pr = pull --rebase
ps = push
lg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(white)<%an>%Creset' --abbrev-commit
lg1 = log --pretty=oneline --abbrev-commit
ci = commit
flg = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(white)<%an>%Creset' --abbrev-commit --remotes --branches
sm = submodule
dt = difftool
7.git详细功能介绍:
a. 忽略指定文件: .gitignore
以“/”开头表示目录;以“?”通配单个字符; 以“*”通配多个字符; 以叹号“!”跟踪某个文件或目录;指出例外的情况,不忽略,如!main.pyc。
b. git中代码的三种状态:unstaged, staged 和 committed
unstaged表示该代码尚未开发完成,staged表示代码开发完成了,准备提交但是尚未提交,committed自然就是提交过的了。
让代码从unstaged变成staged,要通过命令git add <files>和git rm <files>
让代码从staged变成committed,自然要使用命令git commit
c. 设置远程仓库:
添加:git remote add origin git@***.git
删除:git remote remove origin git@***.git
修改:git remote set-url origin git@***.git
查看:git remote -v
初始化:git clone https://github.com/***.git
同步本地分支和远程分支: git remote update -p
d. 分支操作:
创建并切换到新分支:git checkout -b new_branch
新建分支:git branch new_branch
查看当前分支:git branch
本地创建分支并跟踪远程分支:git checkout --track git_branch
合并分支到当前分支: $(master): git merge dev
合并分支但不同步commit:$(master): git merge dev --squash
删除分支: git branch -d new_branch
删除远程分支: git push --delete origin dev
e. 文件比较:
查看两分支的差异: git diff some-branch some-filename.js
查看本地与远程的区别: git diff head fetch_head^
用第三方差异工具查看: git difftool -d
f. 保存尚未提交的改动 git stash ;查看暂存列表:git stash list;恢复暂存:git stash pop
g. 撤销某次提交:git revert -n
h. 删除 一些 没有 git add 的 文件 git clean
j. 保留本地修改,并同步到远程最新分支:
先fetch远程新的修改,git rebase 远程新的分支 ,保留本地修改,并获取最新的远程修改
也可以在本地修改的仓库,fetch远程修改,git merge 远程分支。
k. git clean --dxff
清除所有未跟踪文件,包括纳入ignored的文件
8. 更改Commit号位数
a. 查看commit号位数:git rev-parse --short HEAD
b. 更改commit号位数(以9号为例):git config core.abbrev 9
9. 生成rsa
ssh-keygen -t rsa -C"your_email@youremail.com"
10. 子模块更新
git submodule init
git submodule update