发布于:
2022-05-28 13:57:38
# 安装git
#新的linux使用:
$ sudo apt-get install git
#老版本linux使用:
$ sudo apt-get install git-core
# mac使用
$ brew search git
$ brew install git
# 配置用户名密码
$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"
#通过`git init`命令把这个目录变成Git可以管理的仓库
$ git init
Initialized empty Git repository in /home/study/learngit/.git/
#文件从工作区添加到版本库的暂存区
$ git add readme.txt
#查看文件改动
$ git diff readme.txt
#提交到版本库的某当前某一个分支
$ git commit -m "write a readme file"
#查看所有历史版本
$ git logs
#精简版
$ git log --pretty=oneline
#回退到上一个版本
$ git reset --hard HEAD^
#查看历史版本命令
$ git reflog
#到指定版本 xxxx表示版本号
$ git reset --hard xxxxx
#放弃更改某个文件,从版本库覆盖当前文件
$ git checkout -- <file>
#如果已经跳到暂存区,要重新放回工作区
$ git reset HEAD <file>
#将仓库推送到远程
$ git remote add origin https://gitee.com/cy76/gitlearn.git
$ git push -u origin master
$ git config --global credential.helper store
#分支
#创建dev分支
$ git branch dev
#切换到dev分支
$ git switch dev
$ git checkout dev
$ git checkout -b dev #-b参数表示创建并切换
Switched to a new branch 'dev'
#查看分支
$ git branch
#创建分支:
$ git branch <name>
#切换分支:
$ git switch <name> #或者
$ git checkout <name>
#创建+切换分支:
$ git switch -c <name> #或者
$ git checkout -b <name>
#合并某分支到当前分支:
$ git merge <name>
$ git merge origin/master
$ git merge master
#删除分支:
$ git branch -d <name>
#将远程代码库的代码拉取到工作本机,但不会合并。用户在检查了以后决定是否合并到工作本机分支中
$ git fetch
#忽略文件权限
$ git config core.filemode false
#查看git配置
$ cat .git/config
非特殊说明,本文版权归 陈阳的博客 所有,转载请注明出处.
本文标题: git下载安装,使用教程,开发常用命令整理