Skip to content
This repository has been archived by the owner on Mar 23, 2021. It is now read-only.

git常用命令 & 设置git别名 #2

Open
huguangju opened this issue Oct 30, 2015 · 0 comments
Open

git常用命令 & 设置git别名 #2

huguangju opened this issue Oct 30, 2015 · 0 comments
Labels

Comments

@huguangju
Copy link
Owner

huguangju commented Oct 30, 2015

Git别名

歪果仁写的gitconfig配置文件,sixarm_git_gitconfig: SixArm.com: Git: gitconfig files, aliases, colors, branches, etc., 它可以让你对git的使用如虎添翼。

它主要的别名设置在gitconfig.d/alias.txt下边,现在来好好看看这个文件,相信会收获颇丰。

  ##
  # 一个字别名
  ##

  # add - 将文件内容添加到索引
  a = add

  # branch - 列出,创建或删除分支
  b = branch

  # commit - 记录更改到仓库
  c = commit

  # diff - 查看和上次提交间的变更,提交和工作树,等等
  d = diff

  # fetch - 从远程仓库抓取数据
  f = fetch

  # grep - 搜索工作区中的文件内容
  g = grep

  # log - 显示提交记录
  l = log

  # merge - 合并分支
  m = merge

  # checkout - 切换分支或还原工作树; "o" 代指 "out".
  o = checkout

  # pull - 从远程仓库抓取数据并合并到本地分支,相当于fetch + merge
  p = pull

  # remote - 管理跟踪主机名
  r = remote

  # status - 显示工作树的差异 (高级用户可能更喜欢用: status -sb)
  s = status

  # whatchanged - 查看当前分支的操作记录
  w = whatchanged

Git Tips

同时更新一个目录下的所有git项目

假如我从github clone了N多项目在repos目录下,依次进行每个项目git pull就太累了,以下shell可以帮我们遍历每个目录来执行git pull操作

cd repos
find . -maxdepth 1 -type d -exec sh -c '(cd {} && git pull)' ';'

clone时避免获取仓库的所有历史记录

# 仅获取最新版和一个历史版本,即最后2个版本
git clone https://github.com/nodejs/node --depth=1

Git的几个实用小技巧

git合并特定commits 到另一个分支

git cherry-pick 62ecb3

git rebase -i HEAD~3 压缩提交后无法push

hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.

因为合并的历史记录已经在远程仓库之前了,无法覆盖它。用 git push -f 强制提交就可以了。

more...

扩展阅读:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant