Skip to content

Instantly share code, notes, and snippets.

@albertofwb
Last active August 17, 2017 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertofwb/c23b8152793a4479d11b40adcdf8e1e5 to your computer and use it in GitHub Desktop.
Save albertofwb/c23b8152793a4479d11b40adcdf8e1e5 to your computer and use it in GitHub Desktop.

Git 常用命令总结

在使用git进行团队开发工作中,有些常用命令频繁使用,也有关于git的一些使用技巧。
在这里做一个记录分享给大家。如果有人能从这个文档里得到帮助,我会感到很开心o(* ̄▽ ̄*)ブ。
下面的总结都是本人在实际使用过程中的心得,如果有什么纰漏,请协助我完善这个文档

版本控制

给指定提交打上标签
git tag -a <TagName> <CommitHash>
恢复单个文件到本次提交之前的版本
  1. 查询某个文件的修改记录
git log filePath
  1. 拷贝这个文件需要回退到的commit 记录
git reset commidID filePath
  1. 执行回退操作
git checkout filePath
查看提交日志
git log --oneline --graph --decorate

追踪变更者

查看某个文件中对应的哪一行代码是谁在何时修改的
 git blame FilePath
查看每次commit 涉及的文件
git whatchanged
查看某个文件或者目录的修改历史
git whatchanged  Path
回退某个文件到指定版本的步骤
  1. 查询某个文件的修改记录
git log FilePath
  1. 拷贝这个文件需要回退到的commit 记录
git reset commidID FilePath
  1. 执行回退操作
git checkout FilePath

删除git将要上传的文件

如果有不想上传的文件,但是本地需要保存
git rm --cached FilePath
如果有不想上传的文件夹,但是本地需要保存
git rm -r --cached FilePath

分支管理

创建一个分支
git checkout -b BranchName
切换到一个分支
git branch BranchName
删除本地和远程Git分支

删除本地分支

git branch --delete --force <branchName>

或者使用选项-D作为简写

git branch -D <branchName>
删除远程分支
git push origin --delete <branchName>

或者

git push origin :<branchName>
删除远程分支
git push origin --delete <branchName>
重命名本地分支
git branch -m <oldBranchName> <newBranchName>
合并远程分支到本地
  1. 先切换到主分支
git branch master
  1. 获取最新代码
git fetch
  1. 执行合并操作
git merge origin BranchName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment