Git command

版本切换

  • 切换到某次提交的版本 git reset --hard commit_id

查看日志

  • 查看日志 git log --pretty=oneline
  • 查看日志,可以看到head之后的日志git reflog

commit

  • 追加提交 git commit --amend --no-edit

分支管理

  • 新建分支 git branch <branchname>
  • 切换分支 git checkout <branchname>
  • 新建并切换到新的分支 git checkout -b <branchname>
  • 下载远程分支到本地 git fetch + git checkout <branchname>
  • 删除分支 git branch -d <branchname>
  • 删除远程分支 git push origin --delete <branchname>
  • 修改分支名 git branch -m <old_branch_name> <new_branch_name>如果你在当前分支,可以省略掉<old_branch_name>
  • 修改远程分支名 git push origin :<old_branch_name> <new_branch_name>
  • 隐藏当前修改git stash
  • 回复隐藏的修改git stash pop
  • 合并分支 git merge <branch name>
  • 合并某一次提交 git cherry-pick <commit id>

tag

  • 新建一个标签 git tag <tagname> [<commit>]
  • 查看所有标签 git tag
  • 推送一个本地标签 git push origin <tagname>
  • 推送全部未推送过的本地标签 git push origin --tags
  • 删除一个本地标签 git tag -d <tagname>
  • 删除一个远程标签 git push origin :refs/tags/<tagname>

配置命令别名

git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.st status
git config --global alias.cm commit

切换远程仓库

git remote -v
git remote rm origin
git remote add origin http://xxxxxxx

.ignore 配置

https://github.com/github/gitignore
https://github.com/github/gitignore/blob/master/Android.gitignore

.ignore文件更新后没生效的处理方案

git rm -r --cached .
git add .
git commit -m ".gitignore is now working"

https://stackoverflow.com/questions/1139762/ignore-files-that-have-already-been-committed-to-a-git-repository

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。