Git常用操作

远程分支操作

远程分支操作主要是用来进行feature维护和更新

拉取到本地

操作思路

从零开始,clone一份.git到本地,如果不是,则git fetch相关的远程分支信息到本地,然后将远程分支映射到本地,最后pull即可

具体操作

git clone "XXXX.git"
git fetch
git checkout -b local-branchname origin/remote-branchname
git pull origin remote-branchname

至此可以用git branch查看下载的本地分支信息了

上传到远程分支

直接git push即可

git push origin local-branch:remote-branch

其中,如果remote-branch不存在,会在远程端创建一个新的分支
如果想删除远程分支,local-branch不填写即可,也就是
git push origin :remote-branch

提交更改

最近一次提交日志更改

  • 更改
    git commit --amend

历史提交更改

  • 更改
    git rebase -i version
    如更改上一次的git rebase -i HEAD~
  • 放弃更改
    git rebase --abort
  • 保存更改
    git rebase --continue

git rebase这个功能过于霸道,新手使用前请做好备份...

查看日志

跟踪某个文件的修改

git log specific-file-name
为了简便,可以加上--pretty=oneline参数简化输出
然后使用git show md5进行查看所在的变更

MD5需要输入全部,否则会显示多余的变化

git实用细节

  • 更改自动换行
    git config core.autocrlf false
  • 回退版本新建分支
    checkout commit_id -b new_branck

别名设置

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit 
git config --global alias.br branch
git config --global alias.unstage 'reset HEAD'
git config --global alias.
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容