Git入门使用乱记(持更)

  • 初始化git仓库,生成工做区和版本库
git init
  • 设置用户名与邮箱地址
git config --global user.name 'yourName'

git config --global user.email 'yourEmail'
  • 查看配置信息/具体配置信息(用户名为例)
git config --list
git config user.name
  • 设置默认代码推送分支
git config --global push.default branchName

git config --global push.default master
  • 将文件提交到暂存区,存储在对象库中
git add fileName
  • 将内容提交到指定分支
git commit -m 'comment'
  • 查看提交记录/日志
git log

git log --oneline

git log dirName/fileName
  • 文件重命名
git mv oldFileName newFileName

暂存区文件的修改git

  • 文件删除
git rm -f filename  文件强制删除

git rm --cached filename保留本地文件
  • 操做撤销
git revert HEAD  当前版本,从0开始计算

git revert HEAD~2 当前的第三次
  • 新建分支
git branch branchName
  • 切换分支
git checkout branchName
  • 分支合并
git merge branchName

git merge branchName --no--ff
  • 本地分支删除
git branch -d branchName
  • 删除远端分支
git branch -d branchName

git push --delete origin branchName
  • 分支改动
git diff

git diff branchName1..branchName2
  • 分支重命名
git branch -m oldBranchName newBrachName
  • 建立并切换分支
git checkout -b branchName
  • 分支封存
git stash
  • 分支封存还原
git stash pop
  • 讲本地仓库代码提交到github
<!--切换到须要提交的分支-->
git remote add origin https://github.com/username/test.git
<!--推送提交的内容-->
git push -u origin master
  • 本地分支与远程的对应关系 `
git branch -r
  • 建立分支并关联远端分支
git checkout -b branchName origin/branchName
  • 移除远程关联
git remote remove origin

//恢复使用
git remote add origin https://github.com/username/test.git


//查看关联状况

git remote -v
  • git命令的别名使用
git config --global alias.ci commit
  • 证书秘钥生成

位于~/.ssh中id_rsa和id_rsa.pubgithub

ssh-keygen -t rsa

将id_rsa.pub中内容复制到服务器/home/git.ssh/authorized中服务器

  • 忽略文件操做

在项目目录下新建.gitignoressh

而后中.gitignore中天剑须要忽略的文件日志

相关文章
相关标签/搜索