关于git:git指北

8次阅读

共计 1515 个字符,预计需要花费 4 分钟才能阅读完成。

装置

  • window Git 下载
  • linux 执行 sudo apt-get install git

    // 装置实现之后还须要在命令行进行配置
    git config --global user.name "Your Name"
    git config --global user.email "email@example.com"

    根底概念

    Git 我的项目领有三个阶段

  • 工作区(Working Directory):本地文件目录
  • 暂存区(Staging Ares): 已批改且 add 提交的文件快照区域
  • Git 仓库(Repository): 暗藏目录.git

    根本的 Git 工作流程如下

  • 在工作区中批改文件。
  • 将你想要下次提交的更改选择性地暂存,这样只会将更改的局部增加到暂存区。
  • 提交更新,找到暂存区的文件,将快照永久性存储到 Git 目录。

常用命令

git init  // 创立仓库
git add <file> // 增加文件到暂存区

git conmit -m "commit messages" // 把暂存区的所有内容提交到以后分支
git log // 查看提交日志 --pretty=oneline 参数一行展现
git log --graph --pretty=oneline --abbrev-commit // 查看提交繁难信息
git reflog // 查看命令历史
git status // 查看以后状态
git reset HEAD  <file> // 版本回退  HEAD 代表以后版本

git checkout <name> // 切换分支 
git checkout -- <file> // 回到最近一次 git commit 或 git add 时的状态
git checkout -b <branch-name> origin/<branch-name> // 在本地创立和近程分支对应的分支
git resotre <file> // 从暂存区撤销文件 
git rm -- <file> // 删除文件

git branch // 查看分支
git branch -a // 查看全副近程分支
git branch <name> // 创立分支
git branch -d <name> // 删除分支
git branch --set-upstream-to=origin/<branch-name> <branch-name> // 指定本地分支与近程分支的链接

git switch <name> // 切换分支(举荐)git merge <name> // 合并某分支到以后  --no-ff 可能保留分支信息

git cherry-pick <commit> // 复制提交到以后分支

git stash // 贮存当前工作内容
git stash list // 贮存列表
git stash apply // 复原贮存内容、不删除
git stash apply stash@{0} // 复原指定版本
git stash drop // 删除贮存内容
git stash pop // 复原同时删除贮存内容
git reset // 回退分支记录
git revert // 撤销更改并分享给他人



git remote -v // 查看近程库信息
git pull // 拉取近程代码到本地
git push origin <branch-name>// 推送本地代码到近程

关联近程仓库

  • 获取本地 SSH Key,在用户主目录里找到.ssh 目录,外面有 id_rsa 和 id_rsa.pub 两个文,id_rsa 是私钥,不能泄露进来,id_rsa.pub 是公钥,能够释怀地通知任何人。如果不存在能够在 git base 通过 ssh-keygen -t rsa -C "youremail@example.com" 创立
  • github 创立 repository
// 1 关联近程仓库
git remote add origin <address>
// 2 推送到近程仓库 -u 关联本地 master 和近程 master
git push -u origin master
正文完
 0