• +86 18940128339
  • 3056844889@qq.com

标签归档window

win10 Git安装

1.链接

下载链接 https://git-scm.com/download 本地安装使用默认选项一直下一步即可

2.配置GIt

Git提供了config命令来帮助设置配置信息,在命令行输入:-global 全局进行配置

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

Git提供了config命令来帮助设置配置信息,在命令行输入:

git config --global --list

命令执行结束后可用命令查看配置是否OK

3.Git 创建仓库

Git 使用 git init 命令来初始化一个 Git 仓库,Git 的很多命令都需要在 Git 的仓库中运行,所以 git init 是使用 Git 的第一个命令。也可以给指定空文件夹初始化

git init
git init newrepo
git add . #所有文件
git add -f 文件名 #指定文件夹
git commit -m "注释"
  • git init – 初始化仓库。
  • git add . – 添加文件到暂存区。
  • git commit – 将暂存区内容添加到仓库中。

我们使用 git clone 从现有 Git 仓库中拷贝项目(类似 svn checkout)。

克隆仓库的命令格式为:

git clone <repo>
git clone <repo> <directory>

查看/切换/创建分支

git branch -a 本地 远程 分支
git checkout 分支名
git checkout -b 分支名
git reset --hard

参数说明:

  • repo:Git 仓库。
  • directory:本地目录。

编辑 git 配置文件:

git config -e    # 针对当前仓库 
git config -e --global   # 针对系统上所有仓库

设置提交代码时的用户信息:

git config --global user.name "username"
git config --global user.email demo@username.com

添加远程版本库:

git remote add [shortname] [url]

shortname 为本地的版本库,例如:

 git remote add origin git@github.com:tianqixin/runoob-git-test.git

git pull 命令用于从远程获取代码并合并本地的版本。

git pull <远程主机名> <远程分支名>:<本地分支名>
git pull origin master
git remote -v  # 查看信息

git push 命令用于从将本地的分支版本上传到远程并合并。

git push <远程主机名> <本地分支名>:<远程分支名>
git push origin master

git reset --hard 指定分支回滚

解决每次git pull、git push都需要输入账号和密码

git config --global credential.helper store
git pull
输出:
Username for 'https://git.xxxxxxxx.com': ******
Password for 'https://demo123@163.com': *******

git config [选项]

配置文件位置
    --global              使用全局配置文件
    --system              使用系统级配置文件
    --local               使用版本库级配置文件
    -f, --file <文件>     使用指定的配置文件
    --blob <blob-id>      read config from given blob object

操作
    --get                 获取值:name [value-regex]
    --get-all             获得所有的值:key [value-regex]
    --get-regexp          根据正则表达式获得值:name-regex [value-regex]
    --replace-all         替换所有匹配的变量:name value [value_regex]
    --add                 添加一个新的变量:name value
    --unset               删除一个变量:name [value-regex]
    --unset-all           删除所有匹配项:name [value-regex]
    --rename-section      重命名小节:old-name new-name
    --remove-section      删除一个小节:name
    -l, --list            列出所有
    -e, --edit            打开一个编辑器
    --get-color <slot>    找到配置的颜色:[默认]
    --get-colorbool <slot>
                          找到颜色设置:[stdout-is-tty]

类型
    --bool                值是 "true" 或 "false"
    --int                 值是十进制数
    --bool-or-int         值是 --bool or --int
    --path                值是一个路径(文件或目录名)

其它
    -z, --null            终止值是NUL字节
    --includes            查询时参照 include 指令递归查找