关于git:GIT使用指南

配置相干

git config [--local] [--global] user.name 'name'
git config [--local] [--global] user.email 'email'
// 设置明码过期工夫
git config credential.helper 'cache --timeout=3600'
// 保留明码永不过期
git config --global credential.helper store
// 查看所有配置
git config  --list [--local] [--global] [--system]
// 革除配置
git config --unset 

在windows下全局配置存储地位为

C:\User\用户名\.gitconfig


创立repository

git init your_git_repo
// 或者在当前目录中间接
git init

文件重命名和删除

git mv nameBefore nameAfter
git rm fileToBeDeleted

工作区增加到暂存区 暂存区进行commit

// 将文件的批改和新建增加到暂存区
git add .
// 将文件的批改,新建和删除增加到暂存区
git add -A
git add -all
// 将文件的批改和删除增加到暂存区
git add -u
git commit -m'commit message'

查看历史commit

git log 
git log -3
// 简洁显示
git log --oneline
git log -3 --oneline 
// 查看所有branch的commit历史
git log -a 
// 命令行图形化 intersting 感觉看的不分明
git log --all --graph
// 图形化
gitk --all

分支相干

创立分支

// 新建分支并切换到该分支
git checkout -b branch_name
// 和上面两条命令等价
git branch branch_name
git switch[checkout] branch_name

查看所有分支

git branch
// 显示简略信息
git branch -av

删除分支

// 只有分支中的内容被merge到其余分支能力删除
git branch -d branch_name
// 强制删除
git branch -D branch_name

比拟HEAD,暂存区和工作区的差别

// 比拟HEAD和暂存区的差别
git diff --cached
// 比拟暂存区和工作区的差别
git diff

至于commit之间的差别能够通过图形化界面自行比拟


暂存区复原成HEAD或任意commit(回滚)

// 暂存区复原为HEAD或者任意commit
// soft指的是将HEAD指向指定的commit
// mixed为默认参数 指的是将HEAD和暂存区复原为指定的commit,工作区不变
// hard指的是将HEAD,暂存区和工作区都复原为指定commit
git reset [--soft/hard/mixed] HEAD[commit_hash]

// 工作区复原为暂存区
git restore
git checkout

近程仓库同步

// 查看所有近程仓库
git remote -v
git remote --verbose
// 增加近程仓库
git remote add remote_name remote_address
// fetch将近程仓库拉取到本地 用gitk查看会造成一个独立的分支
git fetch remote_name remote_branch
// 合并本地和远端分支 会新生成一个commit
git merge --allow-unrelated-histories remote_name/remote_branch
// pull等价于fetch加上merge

// push之后 remote_branch的最新commit会指向刚刚merge生成的commit
git push remote_name remote_branch



评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理