• git笔记


    用户信息
    查阅某个环境设定的个人的用户名称和电子邮件地址:
    git config --global user.name 
    git config --global user.email
    
    查看配置信息
    要检查已有的配置信息,可以使用 git config --list 命令:
    
    基本概念
    工作区:就是你在电脑里能看到的目录。
    暂存区:英文叫stage, 或index。一般存放在"git目录"下的index文件(.git/index)中,所以我们把暂存区有时也叫作索引(index)。
    版本库:工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。
    
    git init
    Git 使用 git init 命令来初始化一个 Git 仓库,Git 的很多命令都需要在 Git 的仓库中运行,所以 git init 是使用 Git 的第一个命令。
    在执行完成 git init 命令后,Git 仓库会生成一个 .git 目录,该目录包含了资源的所有元数据,其他的项目目录保持不变(不像 SVN 会在每个子目录生成 .svn 目录,
    
    Git 只在仓库的根目录生成 .git 目录)。
    
    或者使用指定目录作为Git仓库。 git init xxx目录
    
    将文件纳入版本控制,需要先用 git add 命令告诉 Git 开始对这些文件进行跟踪,然后提交:
    g:gitTest>git add 555.txt
    g:gitTest>git commit -m '2222'  //-m提交时输入的备注信息
    [master 7d006e8] '2222'
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 555.txt
    
    
    git clone
    我们使用 git clone 从现有 Git 仓库中拷贝项目(类似 svn checkout)。
    git clone <repo> //repo:Git 仓库 
    g:gitTest>git clone https://github.com/xxx/yyy.git
    Cloning into 'yyy'...
    remote: Counting objects: 6, done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 6 (delta 0), reused 3 (delta 0), pack-reused 0
    Unpacking objects: 100% (6/6), done.
    Checking connectivity... done.
    克隆到指定的目录
    git clone <repo> <directory> //directory:本地目录。
    git clone https://github.com/xxx/yyy.git zzz
    如果要自己定义要新建的项目目录名称,可以在上面的命令末尾指定新的名字:
    
    
    git add 就是说开始跟踪这些文件
    使用 git add . 命令来添加当前项目的所有文件
    
    git status 命令用于查看项目的当前状态。
    g:gitTest>git add .
    g:gitTest>git status
    On branch master
    Changes to be committed: //
      (use "git reset HEAD <file>..." to unstage)
    
            new file:   666.txt
            new file:   git
    
    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)
    
            modified:   555.txt
            modified:   666.txt
            deleted:    git
    
    git commit 使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中。
    Git 为每一个提交都记录你的名字与电子邮箱地址,所以第一步需要配置用户名和邮箱地址。
    g:gitTest>git config --global user.name 'xxx'
    
    g:gitTest>git config --global user.email yyy@qq.com
    
    
    git reset HEAD git reset HEAD 命令用于取消已缓存的内容,就是git add添加的内容
    
    git rm
    git rm 会将条目从缓存区中移除。这与 git reset HEAD 将条目取消缓存是有区别的。 "取消缓存"的意思就是将缓存区恢复为我们做出修改之前的样子。
    默认情况下,git rm file 会将文件从缓存区和你的硬盘中(工作目录)删除。
    如果你要在工作目录中留着该文件,可以使用 git rm --cached:
    g:gitTest>git rm --cached 999.txt
    rm '999.txt'
    
    git mv 移动文件或目录,或是更改其名称,会要求您输入目标文件或目录。
    g:gitTest>git mv 666.txt ooo.txt
    
    
    创建分支命令:git branch (branchname)
    切换分支命令: git checkout (branchname) Git 会用该分支的最后提交的快照替换你的工作目录的内容, 所以多个分支不需要多个目录
    合并分支命令: git merge 
    列出分支: git branch 
    g:gitTest>git branch
    * master
    
    切换分支:
    g:gitTest>echo 12345>1.txt //先创建一个1.txt的文本文件,内容为12345
    g:gitTest>git branch  //列出分支 master为当前分支
      hahah
    * master
    g:gitTest>git add 1.txt //添加文件跟踪
    g:gitTest>git commit -m 'test' //提交到仓库中
    g:gitTest>dir //显示当前分支目录的文件 1.txt
    g:gitTest>git checkout hahah  //切换到hahah分支
    Switched to branch 'hahah'
    g:gitTest>dir //显示当前分支目录的文件 1.txt不存在 ,因为在master分支里
    
    
    删除分支 git branch -d (branchname)
    g:gitTest>git branch -d hahah
    Deleted branch hahah (was 8461214).
    
    分支合并 一旦某分支有了独立内容,希望将它合并到主分支。 
    git merge
    g:gitTest>git merge world
    Updating 410e55d..c372cc8
    Fast-forward
     2.txt | 1 +
     1 file changed, 1 insertion(+)
     create mode 100644 2.txt
    
    git log 查看提交历史
    
    git log --author=xxxx 查找指定用户的提交日志
    
    git log --after=[2016-06-03] 如果要指定日期,可以执行几个选项:--since 和 --before,但是你也可以用 --until 和 --after。
    
    添加远程库 git remote add [shortname] [url]
    
    git remote 查看当前的远程库  
    
    git remote -v 可以看到每个别名的实际链接地址
    
    git fetch  从远程仓库下载新分支与数据  该命令执行完后需要执行git merge 远程分支到你所在的分支。
    
    git pull 从远端仓库提取数据并尝试合并到当前分支
    
    推送到远程仓库 git push <远程主机名> <本地分支名>:<远程分支名>
    
    删除远程仓库  git remote rm [别名]
    
    记住https方式推送密码
    
    方法一: 
    git config credential.helper store  去掉 --global 就可以只为当前项目配置用户名密码了  
    其实配置好后,我们要 push 一次,这次还是得输入帐号密码的,但是下一次 push 就不需要输入了。
    
    G:gitTest>echo 333>3.txt
    
    G:gitTest>git add .
    
    G:gitTest>git commit -m '333'
    [master 7b04ca6] '333'
     1 file changed, 1 insertion(+)
     create mode 100644 3.txt
    
    G:gitTest>git push leyi master:master
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 284 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://git.coding.net/zhangzn3/gitTest.git
       b5475be..7b04ca6  master -> master
    
    方法二:用户名:密码 加到地址里的做法 必须把用户名和密码url编码下才行  encodeURIComponent()
    git remote add origin https://name:password@git.coding.net/xxx/gitTest.git
    

      

     

  • 相关阅读:
    [国家集训队]拉拉队排练 Manancher_前缀和_快速幂
    高手过愚人节 Manancher模板题_双倍经验
    [模板]manacher算法
    [POI2011]MET-Meteors 整体二分_树状数组_卡常
    [国家集训队]矩阵乘法 整体二分
    三维偏序(陌上花开) CDQ分治
    博客园美化之旅第一天(CSS图层关系,背景相关设置,字体相关设置)
    力扣题目解答自我总结(反转类题目)
    python插件,pycharm基本用法,markdown文本编写,jupyter notebook的基本操作汇总
    关于小程序websocket全套解决方案,Nginx代理wss
  • 原文地址:https://www.cnblogs.com/leyi/p/4909704.html
Copyright © 2020-2023  润新知