Git ----> 基本使用

Ubuntu安装最新Git

删除Git

sudo apt-get remove git

下载Git

git clone https://github.com/git/git

安装Git

sudo apt-get install build-essential libssl-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip

cd git

make prefix=/usr/local all

sudo make prefix=/usr/local install

 

Git 基本命令之一

git init 初始化一个git仓库

git add file1 file2 ...  允许把一个或者多个文件添加到仓库

git commit -m "xxxx"  把文件提交到仓库

git commit -am "xxxx"  跳过使用暂存区域,把文件提交到仓库

git status 查看工作区的状态

git diff 查看修改内容

git diff HEAD -- file1 查看工作区和版本库的区别(未提交和已提交)

git log 查看提交历史记录(--pretty=online参数可简化输出内容,内容只包括commit id和添加的内容)(穿梭时空用)

git log --graph --pretty=oneline --abbrev-commit 以图形化的形式查看分支合并情况

git log -1 查看最近一次提交的信息

git log --oneline --decorate 查看各个分支当前所指的对象

git log --oneline --decorate --graph --all 查看分叉历史(输出提交历史,各个分支的指向以及项目的分支分叉情况)

git reset --hard HEAD^ 回退到上一个版本(丢弃提交到仓库的修改)

git reset --hard commit_id 回退到某一个提交历史点(丢弃提交到仓库的修改)

git reflog 查看命令历史(重返未来用)

git checkout -- file1 丢弃工作区的修改,恢复到未修改以前(最近的一次状态);可以把误删除的文件恢复到最新版本

git reset HEAD file1 结合下面的命令,该组合的功能:丢弃暂存区的修改,恢复到未修改以前(最近的一次状态)

git checkout -- file1

git rm file1 结合下面的命令,该组合的功能:删除版本库中的文件

git commit -m "xxxx"

git rm --cached file1 将暂存区中文件不再让Git继续跟踪,但是保留文件在磁盘

git mv file1 file2 结合下面的命令,该组合的功能在Git中对文件改名,把file1改成file2

git commit -m "xxxx"

 

Git 基本命令之二

做好前期准备

git remote add origin github地址 关联一个远程仓库

git push -u origin master 关联后,第一次推送本地仓库master分支的所有内容到远程仓库

git push origin master 本地提交后,可推送最新修改到远程仓库

git clone 仓库地址 克隆远程仓库

git remote -v 查看远程仓库的详细信息

git push origin <branch_name> 从本地推送分支(建议先git pull)

git push origin <tag_name> 从本地推送标签

git push origin --tags 一次性推送全部未推送的标签到远程分支

git checkout -b <branch_name> origin/<branch_name> 在本地创建和远程分支对应的分支(本地和远程分支的名字最好一样)???

git branch --set-upstream <branch_name> origin/<branch_name> 建立本地分支和远程分支的关联???

git pull 抓取远程分支的新提交(建议:先pull,本地合并后再push)

 

Git 基本命令之三

git branch 查看分支

git branch <branch_name> 创建分支

git branch -v 查看每一个分支的最后一次提交

git branch --merged 过滤当前分支列表中已经合并到当前分支的分支

git branch --no-merged 过滤当前分支列表中尚未合并到当前分支的分支

git branch -d <branch_name> 删除分支

git branch -D <branch_name> 强行删除分支

git checkout <branch_name> 切换分支

git checkout -b <branch_name> 创建+切换分支

git merge <branch_name> 合并某分支到当前分支

git merge --no-ff -m "xxxx" <branch_name> 合并分支,但是禁用 fast-forward模式

git stash 把当前工作现场“储藏”起来

git stash list 查看“隐藏的”工作现场

git stash pop 恢复工作现场,并且把stash内容删除

git stash apply stash@{0...} 恢复指定的stash

git stash apply 结合下面的命令,该组合的功能恢复工作现场,并且把stash内容删除

git stash drop

git cherry-pick commit_id 复制一个特定的提交到当前分支 ???

git rebase 把分叉的提交变成直线???

 

Git 基本命令之四

git tag 查看所有标签

git tag <tag_name> 打标签(轻量标签)

git tag <tag_name> <commit_id> 给指定的提交id打标签

git show <tag_name> 查看指定标签的信息

git tag -a <tag_name> -m <message> <commit_id> 创建带有说明的标签(附注标签)

git tag -d <tag_name> 删除标签

git push origin <tag-name> 显式地推送标签到共享服务器上

git push origin --tags 一次性推送很多标签到远程仓库服务器上

git checkout <tag-name> 检出标签,查看某个标签所指向的文件版本

git tag -d <tag_name> 结合下面的命令,该组合的功能:删除一个远程标签

git push origin :refs/tags/<tag_name>

 

Git 基本命令之五

git config ---global alias.<abbrev-name> <commad_part_name> 配置一个代替原来部分命令的单词的别名,例如:

git config --global alias.co checkout

git config <key> 查看某个配置

git config --list 列出所有配置

git help command_name 获取指定命令的帮助文档

 

参考资料:

https://git-scm.com/book/zh/v2

https://www.liaoxuefeng.com/wiki/896043488029600

转载于:https://www.cnblogs.com/mrray1105/p/11360534.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值