本地
命令缩写
- 需求: 我们希望用缩写代替命令,比如使用 git checkout 可以简写为 git co
- 如何实现?
这里可以修改项目下 .git/config 文件
增加 [alias] 选项
[alias]
co = checkout
cb = checkout -b
cp = cherry-pick
cx = cherry-pick -x
st = status
ss = status -s
br = branch
ba = branch -a
cs = commit -s
ca = commit --amend -s
df = diff
dfca = diff --cached
throw = reset --hard HEAD
throwh = reset --hard HEAD^
lg = log --oneline --decorate --color
logs = log --stat --color
dt = difftool
这样就可以实现用缩写代替长串命令了
修改默认的编辑器为 vim
同样可以打开.git/config
修改 [core] 下面的 editor = vim
如何创建一个没有任何历史节点的分支
git checkout --orphan new_branch
使用beyond 对比两个分支的差异
- 设置 Beyond Compare 为默认的 diff 工具。需要安装beyond compare.
设置 Beyond Compare 为默认的 diff 工具
git config --global diff.tool bc3
# 设置 Beyond Compare 为默认的 merge 工具
git config --global merge.tool bc3
# 设置 Beyond Compare 的路径
# 注意:你需要根据你的系统和 Beyond Compare 的实际安装位置来修改这个命令
git config --global difftool.bc3.path "C:/Program Files/Beyond Compare 4/BCompare.exe"
git config --global mergetool.bc3.path "C:/Program Files/Beyond Compare 4/BCompare.exe"
- 对比差异
# 对比当前分支和目标分支的差异
git difftool -d [branchName]
远程
创建远端新分支
假设我们需要在远端新开一个分支用于某个功能的实现
git checkout -b my-test //在当前分支下创建my-test的本地分支分支
git push origin my-test //将my-test分支推送到远程
git branch --set-upstream-to=origin/my-test //将本地分支my-test关联到远程分支my-test上
git branch -a //查看远程分支
gitee
gitee每次操作都提示需要输入密码
git config --global credential.helper store
后面只需要输入以此密码,就可以了。
git 如何传大文件
使用Git-LFS. LFS官网