-
git clone
拉取代码仓库到本地
-
git add xxxx or git add .
添加修改的或是新增的文件到暂存区
-
git commit -m 'xxx'
添加提交记录
-
git fetch
从远端拉取当前分支的最新记录
-
git rebase [branch_name]
将本地commit 衍合到本地对应分支已经跟踪到远程的最新记录之上。branch_name 为空时, 衍合当前分支。
-
git pull
拉取代码并合并。自己很少用这个,基本是在稳定分支上拉取最新代码。
-
git push
推送本地 commit 到远程仓库。
-
git reset --hard commit_hash
-
git checkout -b
基于当前本地分支新建一个分支。
-
git checkout
切换分支
-
git cherry-pick commit-hash
将其他分支的
commit
挑出来合并到当前本地分支。 -
git rebase -i HEAD~xxxx
将当前分支的多少个
commit
进行修正,我通常作为将多个commit
合并用。 -
git push -u origin current_branch_name
将当前新建分支推送到远程。
-
git diff
查看未缓存的修改
-
git diff --cached
查看已被缓存的修改
-
git diff branch_name
当前分支对比branch_name
分支 -
git diff commit-hash
当前HEAD
和commit-hash
对应的commit
对比。 -
git show commit-hash
查看
commit-hash
对应commit
的详细修改, 如果没有commit-hash
则是 当前分支的HEAD
-
git merge
合并两个分支
-
aliases:
ll = log --pretty=format:%C(yellow)%h%Cred%d\ %Creset%s%Cblue\ [%cn] --decorate --numstat
ls = log --no-merges --color --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit
ls-ignored = ls-files --others --i --exclude-standard
far = "!git fetch; git rebase"