git-基础使用(一)

git

普通命令

git init 初始化

自动创建一个分支 master,以及只想master 的一个指针 HEAD

git init

git add 添加文件

添加文件到 暂存区

git add xxxx.file

git commit 提交

保存在本地分支,就是本地 master 上。

git commit -m xxx
命令解析
-m注解

git log 查看历史

查看提交历史记录

git log --pretty=oneline
命令解析
–pretty=oneline显示格式

git reflog 查看所有命令历史

用于往后跳转时,查找log

git reflog

git reset 回退版本

查看回退版本

git reset --hard commitId
命令解析
–hard HEAD^ or commitId回退到某个版本,HEAD:当前版本,HEAD:上一个版本,HEAD^:上上个版本,HEAD~100:第100个版本

git diff 查看版本之间的不同

git diff HEAD -- Readme.md
命令解析
HEAD – fileName查看 fileName 跟上个版本的不同

git checkout 把工作区的修改丢弃

git checkout
命令解析
– fileNamefileName 的工作区的修改全部丢弃

标签命令

对某一时间点的代码打上标签,发布版本时要用到。

git tag

为某个分支当打上 tag,方便发布等。

// show all tags
git tag
// light tag
git tag -a 'v1.0.0'
// tag the code
git tag -a 'v1.0.0' -m 'this is tag'
// delete the tag
git tag -d 'v1.0.0'
命令含义
-l ‘tag_regx’过滤,可以使用通配符
-a ‘tag_name’打上标签
-m ‘commone’加上注释
-s使用 GPG 来打标签
-v验证标签
-d删除tag

git show

显示标签的详细说明

// show detail of the tag
git show 'tag_name'

git tag -a version log_id

如果打tag 之后,发现还有没提交的代码,可以提交之后,添加到tag中

// check log
git log
// add log to the tag
git tag -a v1.0.0 log_id

git push origin tagname

提交tag 需要显式提交,提交到远程服务器。

// push the tag
git push origin v1.0.0
// push all the tags
git push origin --tags

git push origin :refs/tags/v1.0.0

删除远程tag

// delete the remote tag
git push origin :refs/tags/v1.0.0

git checkout tag

切换到指定 tag ,很容易丢失代码,一般使用tag代码创建分支开发。

// checkout the tag, dangerous
git checkout v1.0.0
// create a new branch use the tag
git checkout -b branch1 tag

合并分支

git merge

git merge branch1
参数解析
branch1需要合并的分支

第三方git server 操作

把本地代码上传到 github

  1. 进去本地代码文件夹,git init
  2. git add .
  3. git commit -m “comm”
  4. git remote add origin https://github.com/TimingTop/birmingham.git
  5. git pull --rebase origin master
  6. git pull origin master --allow-unrelated-histories (可选操作)
  7. git push -u origin master

Q&A

1. 如果 .gitignore 不生效

原因是文件之前被加入追踪了,要清除掉,才能生效

git rm -r --cached .
git add .
git commit -m 'update .gitignore'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值