首页 > 其他分享 >3、Git常规操作

3、Git常规操作

时间:2023-03-11 23:11:22浏览次数:50  
标签:Git stash add git 常规 branch 操作 commit 分支

常规操作

https://www.cnblogs.com/ydbk/p/14257920.html

克隆操作

git clone http://git.oschina.net/yiibai/sample.git [自定义目录名称]  # 如果不自定义,就会默认创建 sample目录

分支新建和合并

查看所有分支

git branch -a  #查看本地和远程所有分支
git branch  # 查看本地所有分支
git branch -r  # 查看远程分支
git branch -vv # 查看本地分支对应的远程分支

新建分支

git branch XXX

切换分支

git checkout XXX

切换不存在的分支

git checkout -b XXX   # 如果XXX不存在, 则通过`-b` 参数就会自动创建并切换过去

删除本地分支

git branch -d XXx

删除远程分支

git push origin --delete XXX

reset 三种模式

使用场景:

  1. 修改错误内容,再次commit一次
  2. 使用get reset 命令撤销这一次对的commit

第一种比较直接,但是会留下大量的commit记录。使用git reset就不会

git在本地是有三个区域的:

  • working directory:本地工作区,在这里编写代码
  • stage/index:缓存区,将本地代码暂存
  • history:本地版本库,将暂存区文件提交到本地仓库

三种模式的区别:

  • mixed:不删除工作空间改动代码,撤销commit,并且撤销git add . 操作
  • soft:不删除工作空间改动代码,撤销commit,不撤销git add .
  • hard:删除工作空间改动代码,撤销commit,撤销git add .

撤回已经push的代码

git log  # 查看提交记录
git reset --soft|mixed|hard [HEAD^ | HEAD~1 | commitid]
git push origin master --force

变更操作

git status
git add xxx
git commit

提交更改,可以使用git commit命令,后面跟-m 选项,如果忽略了-m 选项,则会打开一个文本编辑器,我们可以在其中编写多行提交备注信息

在执行 git commit 之前, 一定要先执行 git add 命令

git addgit commit 两个命令可以合为一条

git commit -a -m '备注信息'

查看更改

git log 
commit be24e214620fa072efa877e1967571731c465884
Author: your_name <[email protected]>
Date:   Fri Jul 7 18:58:16 2017 +0800

    ??mark

commit 5eccf92e28eae94ec5fce7c687f6f92bf32a6a8d
Author: your_name <[email protected]>
Date:   Fri Jul 7 18:52:06 2017 +0800

    this is main.py file commit mark use -m option

commit 6e5f31067466795c522b01692871f202c26ff948
Author: your_name <[email protected]>
Date:   Fri Jul 7 18:42:43 2017 +0800

    this is main.py file commit mark without use "-m" option

commit 290342c270bc90f861ccc3d83afa920169e3b07e
Author: Maxsu <[email protected]>
Date:   Fri Jul 7 16:55:12 2017 +0800

    Initial commit//原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/git/git_review_changes.html#article-start

# 使用 git show 命令查看某一次提交详细信息  git show命令才有SHA-1提交ID作为参数
git show be24e214620fa072efa877e1967571731c465884
commit be24e214620fa072efa877e1967571731c465884
Author: your_name <[email protected]>
Date:   Fri Jul 7 18:58:16 2017 +0800

    ??mark

diff --git a/main.py b/main.py
index 91a1389..657c8d0 100644
--- a/main.py
+++ b/main.py
@@ -3,3 +3,5 @@

 print ("Life is short, you need Python !")

+# this is a comment line
+

暂存操作

注意:如果是新增的文件,则是没有办法进行存储的

git stash save "save message": 执行存储时,添加备注
 list: 查看stash了哪些存储
git stash show: 显示做了哪些改动
git stash apply: 应用某个存储,默认是第一个即 git stash apply stash@{0},如果要使用其他的存储,git stash apply stash@{1}
git stash pop: 回复之前缓存的工作目录,并将其从stash中删除,默认是第一个 stash@{0}, 如果要恢复其他stash,git stash pop stash@{1}
git stash drop stash@{num}: 丢弃stash@{num}的存储
git stash clear: 删除所有暂存的stash
python -c "import socket,SocketServer,CGIHTTPServer;SocketServer.TCPServer.address_family=socket.AF_INET6;CGIHTTPServer.test()" 8080

标签:Git,stash,add,git,常规,branch,操作,commit,分支
From: https://www.cnblogs.com/xuejian123/p/17204322.html

相关文章

  • Git rebase 与 merge
    合并分支在开发过程中,会有许许多多的分支,但每一个仓库都有一个核心分支——main分支,用于发布稳定版本的分支。其余的分支开发完成一个功能或修复一个BUG之后都是要与......
  • appium的部分操作汇总
    ##安装[Appium自动化环境搭建保姆级教程-掘金](https://juejin.cn/post/7069774917641699364)[技术好文|百分百成功搭建appium自动化测试详细教程](https://mp.weix......
  • git将本地文件传到gitee中
    一,文件上传到gitee1.先在gitee中新建一个仓库获取地址:[email protected]:weixinwen/practice.git如下图2.简易的命令行入门教程:Git全局设置:gitconfig--globaluser.......
  • 笔记五:git团队协作
    一:学习内容git团队内协作git跨团队协作 二:git团队内协作用案例来说明步骤:1.师傅岳不群创建了一套华山剑法,把它推送到代码托管中心远程库2.弟子令狐冲将整套剑法下......
  • 对象操作流_序列化和反序列化
    publicstaticvoidmain(String[]args)throwsIOException,ClassNotFoundException{//对象如果想操作流,这个对象的类需要实现Serializable接口/......
  • 笔记四:git分支
    一:学习内容git分支特性git分支操作-查看分支git分支操作-创建分支git分支操作-切换和修改分支git分支操作-分支合并git分支操作-代码合并冲突解决 二:git分支特......
  • 笔记三:git常用命令
    一:学习内容1、设置用户签名:gitconfig--globaluser.name用户名gitconfig--globaluser.email邮箱2、操作本地库:初始化本地库:gi......
  • 笔记二:git安装
    一:学习内容git安装步骤详解 二:git下载-基于官网发布最新版本1.git下载官方网址【如果这个慢就用2】:https://git-scm.com/download/win2.git下载镜像网址:https://n......
  • [操作系统] - 进程关系之同步互斥
    同步与互斥临界区&临界资源临界资源(CriticalResouce):一次仅允许一个进程使用的共享资源临界区(criticalsection):每个进程中访问临界资源的那段代码临界区进入......
  • 笔记一:git简介
    一:学习内容git是什么git版本控制(重点:分布式版本控制工具VS集中式版本控制工具)git工作机制git和代码托管中心 二:git是什么git是一个免费的、开源的分布式版本控......