Git安装及基本操作

1.安装Git

配置用户

git config --global user.name "用户名"
git config --global user.email "邮箱"

配置完成后查看配置

git config -l

Git安装及基本操作_第1张图片

生成SSH秘钥

ssh-keygen -t rsa -C “邮箱” 输入完成后需要按3次Enter键

$ ssh-keygen -t rsa -C "邮箱"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/daqsoft/.ssh/id_rsa):
Created directory '/c/Users/daqsoft/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/daqsoft/.ssh/id_rsa
Your public key has been saved in /c/Users/daqsoft/.ssh/id_rsa.pub
The key fingerprint is:

去到上面的路径下查看文件是否已经生成
Git安装及基本操作_第2张图片

2.创建本地Git仓库

mkdir demo1 创建文件夹
cd demo1/ 进入到路径
git init 创建git仓库

daqsoft@DESKTOP-HKFK5RH MINGW64 /
$ mkdir demo1    

daqsoft@DESKTOP-HKFK5RH MINGW64 /
$ cd demo1/

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1
$ git init
Initialized empty Git repository in E:/GIT/demo1/.git/

路径下多可一个.git的文件了,这个文件夹用来跟踪管理版本库

Git安装及基本操作_第3张图片

Git安装及基本操作_第4张图片

提交本地文件到Git

vim demo.txt 创建测试文件,输入hello word 1 编辑完成后按Esc,然后:wq保存并退出
git status 查看Git仓库的状态,状态有修改、删除、增加

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ vim demo.txt

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ git status
On branch master

No commits yet

Untracked files:   (表示还没有被跟踪的文件)
  (use "git add ..." to include in what will be committed)
        demo.txt

nothing added to commit but untracked files present (use "git add" to track)

git add 文件名 添加到暂存区

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ git add demo.txt
warning: LF will be replaced by CRLF in demo.txt.
The file will have its original line endings in your working directory

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ git status
On branch master

No commits yet

Changes to be committed:   (表示还没有被提交的文件)
  (use "git rm --cached ..." to unstage)
        new file:   demo.txt

git commit -m “add demo.txt file” 把demo.txt提交修改
这里后使用git status查看状态,就没有了就表示提交成功了
git log 查看历史提交记录

创建分支

git branch 分支名 创建分支
git switch 分支名 切换到分支

Git安装及基本操作_第5张图片

到了分支后,创建一个测试文本文件,然后添加到暂存区,然后提交到git仓库(这个过程和场面差不多)
此时分支下使用ll命令可以查看到我新创建的fzDemo.txt文本文件

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (fz1)
$ ll
total 2
-rw-r--r-- 1 daqsoft 197121 14 1224 09:25 demo.txt
-rw-r--r-- 1 daqsoft 197121 17 1224 09:57 fzDemo.txt

使用git switch master命令切换到master分支再使用ll命令,这个分支下没有fzDemo.txt文件,此时就要进行下一个操作合并分支

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ ll
total 1
-rw-r--r-- 1 daqsoft 197121 14 1224 09:25 demo.txt

合并分支

git merge fz1 输出表示新增了一个fzDemo.txt文件,然后再用ll查看,此时fzDemo.txt就被合并到master这个分支来了

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ git merge fz1
Updating 5523978..e5842d7
Fast-forward
 fzDemo.txt | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 fzDemo.txt

daqsoft@DESKTOP-HKFK5RH MINGW64 /demo1 (master)
$ ll
total 2
-rw-r--r-- 1 daqsoft 197121 14 1224 09:25 demo.txt
-rw-r--r-- 1 daqsoft 197121 17 1224 10:04 fzDemo.txt

你可能感兴趣的:(配置文件,git,elasticsearch,大数据)