包含标签 git articles

git log介绍

查看

1
$ git log

简化版日志

1
$ git log --pretty=oneline

查看前N条

1
git log -n

变更日志

-n 同上,不加则显示全部

……

Continue reading

git Version Control介绍

初始化一个Git仓库

1
$ git init

添加文件到Git仓库

1
2
$ git add <file>
$ git commit -m "description"

git add可以反复多次使用,添加多个文件,git commit可以一次提交很多文件,-m后面输入的是本次提交说明。

……

Continue reading

git 远程仓库介绍

创建SSH Key

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ ssh-keygen -t rsa -C "[email protected]"

Generating public/private rsa key pair.  # 生成密钥对 
Enter file in which to save the key (/root/.ssh/id_rsa):  # 保存路径
Enter passphrase (empty for no passphrase):   # 密码,默认空
Enter same passphrase again:   # 重复密码
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
92:41:73:6d:ba:03:bf:36:f8:ab:a2:90:0c:9c:a1:85 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|      o ..       |
| .   . o  o      |
|E..   .  o       |
|o.o   .o.        |
|oo    ooS.       |
|o.     .+        |
|o.     . o       |
| .  . . +        |
|  .. ..+oo       |
+-----------------+

关联远程仓库

1
git remote add origin [email protected]:git_username/repository_name.git

添加后,远程库的名字就是origin

……

Continue reading

git基础介绍

Git配置

1
2
$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

git config命令的--global参数,表明这台机器上的所有Git仓库都会使用这个配置,也可以对某个仓库指定不同的用户名和邮箱地址。

……

Continue reading

git提交代码到github提示失败

1、报错信息

Connection reset by 20.205.243.166 port 22 fatal: Could not read from remote repository.  Please make sure you have the correct access rights and the repository exists.

2、处理方案

尝试将host文件中添加
192.30.255.112 github.com git
185.31.16.184 github.global.ssl.fastly.net
……

Continue reading

git常用的操作

git常用的操作语法介绍

1、回归合并代码的请求

git checkout . && git clean -xdf

2、强制删除本地的代码分支

git branch -D branchName

3、检出代码到本地

git checkout -b 本地分支名 远程分支名
……

Continue reading

git本地未提交被丢弃的文件如何找回

1、问题背景

写了一天代码,下班的时候随手关闭sourceTree,然后在关闭之前顺手执行了丢弃操作。(以为是测试项目的代码,无需保留)。下一秒猛地意识到是今天的项目代码。突然紧张起来了。

……

Continue reading