Git的基本操作

Git使用

为什么使用 Git
Git tutoria
Git 说明书

常用命令

一般步骤

cd // 工作文件夹
git init // 初始化,创建一个.git子目录
git add *.c // 追踪指定文件
git add -A // 追踪所有文件
git commit -m 'initial project version' // 无-m进编辑器写说明 -a 跳过暂存直接提交 --amend 重新提交

git remote add <shortname> <url> // 添加一个新远程git仓库
git fetch <shortname> // 拉取远程仓库有本地无的信息

git push <remote> <branch> // 提交到远程仓库 -u -f 强行

分支与合并

git branch // 查看当前分支 --no-merged 查看未合并工作的分支
git branch testing // 新testing分支
git checkout testing // 切换到新创建的分支 git checkout -b testing 简写
git merge testing // 将testing合并到当前分支
git add -- // 冲突已解决
git branch -d testing // 合并后删除该分支

基本命令

git config --global user.name "John Doe" // 配置用户名及邮件地址,一次即可,对特定项目使用不同地址,去掉--global
git config --global user.email johndoe@example.com

git config --global core.editor emacs // 更换文本编辑器(如emacs

git config --list --show-origin // 查看配置及所在文件
git config --list // 检查配置
git config user.name // 检查一项配置(如user.name
git help config // 获取命令手册(如config

克隆现存仓库

git clone https://github.com/?/! # 克隆到一个文件夹,名为!
git clone https://github.com/?/! name # 新的目录名

其他常用命令

git status // 查看文件状态 -s 紧凑输出
git diff // 显示变化
echo 'My Project' > README
rm A.md // 移除文件
git mv old new // 改名
git log // 时间先后列出提交 -p 每次提交的差异
git reset HEAD <file> // 取消暂存
git checkout -- <file> // 撤销修改,回到上一次提交状态

git remote // 查看远程仓库 -v 显示简写与url
git remote rename <OldName> <NewName> // 修改一个远程仓库简写
git remote remove paul // 移除一个远程仓库

git tag // 列出标签
git tag -l "v1.8.5*"// 列出标签
git tag -a v1.4 -m "my version 1.4" // 附注标签
git tag v1.4 // 轻量标签
// 后期打标签
git log --pretty=oneline // 列出所有提交校验和
git tag -a v1.2 9fceb02 // 对应部分校验和
git push origin v1.5 // 共享标签
git push origin --tags // 推送所有标签
git tag -d v1.4-lw // 删除一个标签
git tag origin --delete <tagname> // 删除远程标签

git rebase master // 变基
// https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%8F%98%E5%9F%BA

忽略一些文件

同时提交到gitee和github

  • 新建两个空白仓库后
  • .git隐藏文件夹(文件夹左上角-查看-隐藏的项目)
  • 记事本打开config文件,补充Gitee/Github的仓库地址
[remote "origin"]
	url = https://gitee.com/Wind_to_valley/notes.git
	url = https://github.com/ouzhoucheng/Notes.git
	fetch = +refs/heads/*:refs/remotes/origin/*

git服务器

服务器上的git协议

  • 本地协议:共享文件系统,有服务器则简单,系统难配置,比ssh慢,不够安全
  • (智能)HTTP协议:比ssh简单,某些服务器更麻烦
  • SSH协议:简单,安全,高效,不匿名
  • Git协议:最快,没有授权机制,最难架设

在服务器上搭建git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值