笔记——开发必备的Git辅助文

之前记笔记写的手疼,现在笔记主要靠敲键盘,完了!键盘都发光了~

写这篇文章原因:因为本人老是忘记Git命令【以后很大概率老年痴呆症,现在要多赚钱】不瞎扯啦!开始正题~

1.Git下载地址

https://git-scm.com/ win64不行可以用我百度网盘下载地址:

【链接:https://pan.baidu.com/s/1GaXZEspfeQ_t4x_LJFouHg 提取码:5201】

2.Git安装

这一步我真没啥说 ,下载完双击执行安装,然后一直下一步【觉得自己不保险,就去找一个图文教程吧!我也没有mac啥的,就只能简单的说win64安装】完成安装之后,就可以使用命令行的 git 工具(已经自带了 ssh 客户端)了,另外还有一个图形界面的 Git 项目管理工具。在开始菜单里找到"Git"->"Git Bash",会弹出 Git 命令窗口,你可以在该窗口进行 Git 操作。【win的安装真正很简单】Linux安装可以点击跳过去看一下官网

3.Git配置

下面可能是你使用git config常用的命令:

git config --list        #查看配置信息


编辑git配置文件
git config -e            # 针对当前仓库 
git config -e --global   # 针对系统上所有仓库


【举例说明】
# 设置提交代码时的用户信息
$ git config --global user.name "runoob"
$ git config --global user.email test@runoob.com   

下面是git config所有命令:

usage: git config [<options>]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    --worktree            use per-worktree config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

Action
    --get                 get value: name [value-pattern]
    --get-all             get all values: key [value-pattern]
    --get-regexp          get values for regexp: name-regex [value-pattern]
    --get-urlmatch        get value specific for the URL: section[.var] URL
    --replace-all         replace all matching variables: name value [value-pattern]
    --add                 add a new variable: name value
    --unset               remove a variable: name [value-pattern]
    --unset-all           remove all matches: name [value-pattern]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    --fixed-value         use string equality when comparing values to 'value-pattern'
    -e, --edit            open an editor
    --get-color           find the color configured: slot [default]
    --get-colorbool       find the color setting: slot [stdout-is-tty]

Type
    -t, --type <>         value is given this type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --bool-or-str         value is --bool or string
    --path                value is a path (file or directory name)
    --expiry-date         value is an expiry date

Other
    -z, --null            terminate values with NUL byte
    --name-only           show variable names only
    --includes            respect include directives on lookup
    --show-origin         show origin of config (file, standard input, blob, command line)
    --show-scope          show scope of config (worktree, local, global, system, command)
    --default <value>     with --get, use default value when missing entry

后面简短的英文解释还是比较好懂的,实在不懂我们就复制翻译一下或者看一下别人怎么用的。

4.Git关于项目常用命令

比如当你在Gitee - 基于 Git 的代码托管和研发协作平台创建了一个新仓库,就会看到这样的页面

一般分https地址或者git地址,上面所有命令一般就是你新建仓库时常用的命令,当然上面少了git  clone 【当你需要拷贝项目可以使用git clone】

git clone  #从现有 Git 仓库中拷贝项目

上图的命令我相信大家都懂,那就只简单的把命令放下面记录一下吧!【Git 全局设置在上面已经有啦!就不继续放咯!】

创建 git 仓库:

mkdir zby_app
cd zby_app
git init 
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/zby/zby_app.git
git push -u origin "master"


已有仓库?

cd existing_git_repo
git remote add origin https://gitee.com/zby/zby_app.git
git push -u origin "master"

算了!再备注一下吧!

初始化git仓库

git init 

【举例说明】
1.cd newrepo
2.git init
执行完,就会在 newrepo 目录下会出现一个名为 .git 的目录

提交文件到仓库

git add .       #所有文件
git add *.c     #将目录下以 .c 结尾文件提交到仓库中
git add README  #将目录下 README 文件提交到仓库中

添加代码提交说明

git commit -m '提交说明文案'

推送代码到远程仓库

因为一般先提交到本地仓库【我不想解释Git 工作区、暂存区和版本库肿么办?如果让你们直接去Git 工作区、暂存区和版本库 | 菜鸟教程  看会不会怼我?】

git push	#上传远程代码并合并

git push与之对应的还有git pull

git pull	#下载远程代码并合并

当然啦!其中就会涉及到git remote

git remote	 #远程仓库操作

【举例说明】
$ git remote
origin
$ git remote -v
origin  127.0.0.1:/data/git/zby/zby (fetch)
origin  127.0.0.1:/data/git/zby/zby (push)


gitee图中git remote add就是
git remote add [shortname] [url]    #添加一个新的远程仓库

【举例说明】
$ git remote add origin git@github.com:zby/zby-git-test.git


那么推送和拉取的远程仓库代码中的 origin你明白了吗?
【举例说明】
git push [alias] [branch]   # 推送你的新分支与数据到某个远端仓库命令

#下面这个命令是 推送到远程仓库origin   master是你的分支【branch】
git push -u origin master或者git push origin master    

对应的git pull origin master就不解释了

最后就是 git remote rm [别名]   #删除远程仓库【谨慎使用】

上面讲着讲着就涉及到了分支,那就开始git branch

代码仓库的分支和标签

git branch                   #列出分支基本命令
git branch (branchname)      #创建分支命令
git checkout (branchname)    #切换分支命令
git branch -d (branchname)   #删除分支命令



【举例说明】
$ git branch
* medical

$ git branch zby

$ git branch
* medical
  zby

$ git checkout zby

$ git branch
  medical
* zby


这里的话有一个git checkout可以注意一下

分支的话一般就会get到合并分支git merge

git merge    #合并分支命令

【举例说明】

$ git branch
* master
  newtest

$ ls
README        test.txt

$ git merge newtest
Updating 3e92c19..c1501a2
Fast-forward
 runoob.php | 0
 test.txt   | 1 -
 2 files changed, 1 deletion(-)
 create mode 100644 runoob.php
 delete mode 100644 test.txt

$ ls
README        runoob.php

git merge一般还跟git fetch有点关系!

git fetch  [别名]   #远程仓库下载新分支与数据
git merge  [别名]   #远端仓库提取数据并尝试合并到当前分支

【备注】 使用git fetch命令执行完后需要执行 git merge 远程分支到你所在的分支。

【举例说明】

我们在本地更新修改
$ git fetch origin
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:tianqixin/runoob-git-test
   0205aab..febd8ed  master     -> origin/master

以上信息"0205aab..febd8ed master -> origin/master" 说明 master 分支已被更新,然后我们就可以使用以下命令将更新同步到本地:

$ git merge origin/master
Updating 0205aab..febd8ed
Fast-forward
 README.md | 1 +
 1 file changed, 1 insertion(+)

最后是顺便说一下git tag【不是我顺便说它就不重要哈!】

git tag   #查看所有标签

git tag 主要用来打标签,比如说版本标签
【举例说明】git tag -a v1.0 命令给最新一次提交发布代码打上(HEAD)"v1.0"的标签
【备注  -a 选项意为"创建一个带注解的标签"】


git tag -a <tagname> -m "runoob.com标签"  #指定标签信息命令
git tag -s <tagname> -m "runoob.com标签"  #PGP签名标签命令

5.Git不常用命令

git status	         #查看仓库当前的状态,显示有变更的文件。
git diff	         #比较文件的不同,即暂存区和工作区的差异。
git reset	         #回退版本。
git rm	             #删除工作区文件。
git mv	             #移动或重命名工作区文件。
git log	             #查看历史提交记录
git blame <file>	 #以列表形式查看指定文件的历史修改记录

最后有可能git clone需要ssh密钥认证,所有我们需要生成ssh公钥私钥

6.Git密钥

ssh-keygen命令用于为“ssh”生成、管理和转换认证密钥,它支持RSA和DSA两种认证密钥.

ssh-keygen(选项)

-b:指定密钥长度; 
-e:读取openssh的私钥或者公钥文件; 
-C:添加注释; 
-f:指定用来保存密钥的文件名; 
-i:读取未加密的ssh-v2兼容的私钥/公钥文件,然后在标准输出设备上显示openssh兼容的私钥/公钥; 
-l:显示公钥文件的指纹数据; 
-N:提供一个新密语; 
-P:提供(旧)密语;
-q:静默模式; 
-t:指定要创建的密钥类型。

Git Bash执行效果:

$ ssh-keygen.exe  # 或者ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/admin/.ssh/id_rsa): 123456
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in 123456
Your public key has been saved in 123456.pub
The key fingerprint is:
SHA256:7wdkzp6kE/OCl5I8EEyrVpE9vFzSHEarxyIZjIHqdis admin@DESKTOP-B6614IH
The key's randomart image is:
+---[RSA 3072]----+
| ..  + ++.       |
|.  ++ =.+.       |
|. .oo+ =.        |
|.   =ooo  o      |
|.  oo.o S=       |
| oo... oo.=      |
|... .o o O.o     |
| E .  * *.+ .    |
|  .    + o..     |
+----[SHA256]-----+

admin@DESKTOP-B6614IH MINGW64 /
$ ls
123456  123456.pub  demo/  java_tools/  vhr/

我上面都有输入123456,其实你可以直接回车就好了【win一般你没有设置生成地址,它都会在你C盘用户下面.ssh文件夹下面可以找到。解释一下123456.pub 文件是你的公钥   123456文件则是与之对应的私钥】

完结!撒花~~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZBY52031

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值