git版本控制安装、配置与使用:

1.下载git

下载地址:git官网
按照如图所示进行下载

在这里插入图片描述

2.解压git

下载到合适的目录下
在这里插入图片描述

3.配置git环境环境变量

1.计算机–>系统高级设置–>环境变量–>系统环境变量–>Path–>编辑
注意:是bin文件夹所在的目录
在这里插入图片描述
2.验证是否配置成功:在终端中输入指令进行验证

Microsoft Windows [版本 10.0.19041.208]
(c) 2020 Microsoft Corporation. 保留所有权利。
C:\Users\Administrator>git -v
git version 2.39.0.windows.1
C:\Users\Administrator>
C:\>bash
Administrator@wx MINGW64 /c
$ git -v
git version 2.39.0.windows.1
Administrator@wx MINGW64 /c
$ git --help
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--
bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>] [--config-env=<name>=<envvar>]
<command> [<args>]
These are common Git commands used in various situations:
start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one
work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
restore Restore working tree files
rm Remove files from the working tree and from the index
examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
diff Show changes between commits, commit and working tree, etc
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status
grow, mark and tweak your common history
branch List, create, or delete branches
commit Record changes to the repository
merge Join two or more development histories together
rebase Reapply commits on top of another base tip
reset Reset current HEAD to the specified state
switch Switch branches
tag Create, list, delete or verify a tag object signed with GPG
collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local
branch
push Update remote refs along with associated objects
'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.
Administrator@wx MINGW64 /c
$

查看git版本信息
git -help

C:\Users\Administrator>git -help
unknown option: -help
usage: git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | -P | --no-pager] [--no-replace-objects] [--
bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
[--super-prefix=<path>] [--config-env=<name>=<envvar>]
<command> [<args>]

4.git常用命令:

4.1.克隆远程仓库:

使用 git clone 远程仓库地址 命令进行远程仓库的克隆

git clone https://gitee.com/gz-yami/mall4j.git

显示结果为:

Cloning into 'mall4j'...
remote: Enumerating objects: 6529, done.
remote: Counting objects: 100% (1242/1242), done.
remote: Compressing objects: 100% (1002/1002), done.
remote: Total 6529 (delta 504), reused 230 (delta 34), pack-reused 5287
Receiving objects: 100% (6529/6529), 14.45 MiB | 2.32 MiB/s, done.
Resolving deltas: 100% (3138/3138), done.

说明克隆成功。

4.2.使用git推送文件到远程仓库

1.打开想要推送的文件夹,在终端中使用git init命令将本其初始化为git仓库。
在这里插入图片描述
2.在终端中使用git add * 命令添加文件到暂存区(.git文件夹),使用git commit 命令提交代码到本地仓库
注意: 暂存区和本地仓库都是git版本库的内容。

C:\Users\Administrator\Desktop\htmlcss>git add *
C:\Users\Administrator\Desktop\htmlcss>git commit -m init
[master (root-commit) 2a67031] init
1 file changed, 10 insertions(+)
create mode 100644 index.html
C:\Users\Administrator\Desktop\htmlcss>git status
On branch master
nothing to commit, working tree clean
C:\Users\Administrator\Desktop\htmlcss>

3.使用git push 将本地git仓库推送到远程仓库
注意: 使用git push推送前要先进行git的配置,另外git push -u origin “master” 中的 "-u"目的是为了下次推送本地仓库可以直接写git push就可以

#配置git信息
git config --global user.name webrx
git config --global user.email [email protected]
#查看全局配置信息
C:\Users\Administrator>git config --global --list
user.name=webrx
user.email=[email protected]
safe.directory=D:/note
safe.directory=D:/soft/es
#添加文件并提交
git add *
git commit -m xxxx
#进入gitee.com ,建立好es.git空项目
#设置本地git版本库远端的仓库地址
git remote add origin https://gitee.com/webrx/es.git
#推项目,此时需要gitee账号密码相关信息
git push -u origin "master"
#以后操作
git add *
git commit -m xxx
git push
C:\Users\Administrator\Desktop\htmlcss>git add *
C:\Users\Administrator\Desktop\htmlcss>git commit -m "first commit"
[master (root-commit) f4e1dd4] first commit
1 file changed, 10 insertions(+)
create mode 100644 index.html
C:\Users\Administrator\Desktop\htmlcss>git remote add origin
https://gitee.com/webrx/htmlcss.git
C:\Users\Administrator\Desktop\htmlcss>git push -u origin "master"
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 383 bytes | 383.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/webrx/htmlcss.git
* [new branch] master -> master
branch 'master' set up to track 'origin/master'.
wechat:webrxwp - mobile:13014577033 - email:[email protected] - qq:7031633
11 / 35
git pull 拉取到本地
C:\Users\Administrator\Desktop\htmlcss>git push -u origin "master"
Everything up-to-date
branch 'master' set up to track 'origin/master'.
C:\Users\Administrator\Desktop\htmlcss>git add *
C:\Users\Administrator\Desktop\htmlcss>git commit -m index.css建立
[master d51bc03] index.css建立
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 css/index.css
C:\Users\Administrator\Desktop\htmlcss>git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (4/4), 323 bytes | 323.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/webrx/htmlcss.git
f4e1dd4..d51bc03 master -> master

这里是以gitee中的仓库为例:

扫描二维码关注公众号,回复: 15485519 查看本文章

在这里插入图片描述

4.3 拉取远程仓库代码到本地

使用git pull 命令将远程仓库中的代码更新到本地

git pull 

注意: 如果想要把克隆的别人的文件传送到自己的远程仓库,需要先删除克隆的.git文件夹,再进行推送,直接推送将会报错。

猜你喜欢

转载自blog.csdn.net/qq_46108215/article/details/128838909
今日推荐