[转载]常用 Git 命令清单

http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html

 

摘出几个git命令

 

# 删除远程分支

$ git push origin --delete [branch-name]

 

# 选择一个commit,合并进当前分支

$ git cherry-pick [commit]

 

# 建立追踪关系,在现有分支与指定的远程分支之间

$ git branch --set-upstream [branch] [remote-branch]

 

# 使用一次新的commit,替代上一次提交

# 如果代码没有任何新变化,则用来改写上一次commit的提交信息

$ git commit --amend -m [message]

 

# 重做上一次commit,并包括指定文件的新变化

$ git commit --amend [file1] [file2] ...

 

# 删除工作区文件,并且将这次删除放入暂存区

$ git rm [file1] [file2] ...

 

# 停止追踪指定文件,但该文件会保留在工作区

$ git rm --cached [file]

 

# 改名文件,并且将这个改名放入暂存区

$ git mv [file-original] [file-renamed]

 

 

Git的设置文件为.gitconfig,它可以在用户主目录下(全局配置),也可以在项目目录下(项目配置)。

# 显示当前的Git配置

$ git config --list

 

# 编辑Git配置文件

$ git config -e [--global]

 

# 设置提交代码时的用户信息

$ git config [--global] user.name "[name]"

$ git config [--global] user.email "[email address]"

 

# 显示某个文件的版本历史,包括文件改名

$ git log --follow [file]

$ git whatchanged [file]

 

# 显示指定文件相关的每一次diff

$ git log -p [file]

 

# 显示暂存区和工作区的差异

$ git diff

 

# 显示暂存区和上一个commit的差异

$ git diff --cached [file]

 

# 显示工作区与当前分支最新commit之间的差异

$ git diff HEAD

 

# 显示两次提交之间的差异

$ git diff [first-branch]...[second-branch]

 

# 显示某次提交发生变化的文件

$ git show --name-only [commit]

 

# 显示某次提交时,某个文件的内容

$ git show [commit]:[filename]

 

# 恢复某个commit的指定文件到工作区

$ git checkout [commit] [file]

 

# 生成一个可供发布的压缩包

$ git archive

猜你喜欢

转载自20142014.iteye.com/blog/2263260