GIT使用基础

新建git 项目  

    git init

添加文件 

    git add . 

    git add *.c 

删除文件

    git rm file.text (删除文件跟踪)

    git rm -f file.test (删除之前添加的记录)

    git rm --cached fill.text (仅删除git 不删本地)

移动文件

    git mv from_file.test to_file.test

提交添加 

    git commit -m '注释'

    git commit -a -m '注释'   // -a 自动添加所有已跟踪过的文件更新(跳过git add)

克隆项目 

    git clone https/ssh_url

查看项目修改状态(文件)

    git status

    git status -s  简览

        左边暂存区 右边工作区 -- A新添加 M修改过 

查看项目修改内容

    工作区与暂存区:git diff    

    暂存区与最后一次提交:git diff --staged   / git deff --cached

忽略文件

    cat .gitignore

        子目录可独立配置

        demo:https://github.com/github/gitignore

查看提交历史

    git log

    git log -p  // 显示差异(详细)

    git log -p -2  // 显示最近两次提交

    git log -stat  // 仅显示文件行数差异

    git log ----pretty=online  // 格式化输出   online / short / full / fuller / format: "%h ...."  https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2#pretty_format

    git log --since=2.weeks  // 最近两周的提交

    git log  --oneline --decorate  // 查看head指向当前所在分支

    git log --oneline --decorate --graph --all  // 查看分支分叉情况

重新暂存

    git commit --amend  // 在未完成push之前重新修改提交的文件

取消暂存

    git reset HEAD file.txt

撤销修改

    git checkout -- file.txt

查看远程仓库

    git remote -v

添加远程仓库

    git remote add <shortname> https/ssh://url

从远程仓库拉取

    git fetch <remote>

        clone 的仓库 默认名为 origin

        git pull

推送到远程仓库

    git push origin master

    git push origin v1.5  // 推送指定标签到远程

    git push origin --tags // 推送所有标签到远程

    git push origin --delete v1.1.1  // 远程删除标签

查看远程仓库

    git remote show origin

远程仓库重命名

    git remote rename <oldname> <newname>

远程仓库删除

    git remote remove <name>

 

列出标签

    git tag

    git tag -l '1.8.5*'

创建标签

    git tag -a v1.1.1 -m 'test'

    git tag v1.1.1  // 轻标签  git show 无信息

    git tag -a v1.2.2 <hash>  // 为已经提交过的历史添加标签

查看标签内容

    git show v1.4

标签删除

    git tag -d v1.1.1

 

创建分之

    git branch  // 获取当前所有分支列表

    git branch -v // 查看分支最后一次提交

    git branch --merged / --no-merged // 忽略已经合并/未合并的分支

    git branch testing

    git branch -b testing  // 创建后切换到分支

切换分支

    git checkout testing 

分支合并

    git merge testing

删除分支

    git branch -d testing

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值