GIT工具-------代码远程仓库管理

### GIT

  第一步:  ## 设置用户名邮箱

0. git config --global user.name "Kervin"

1. git config --global user.email "@163.com"  #邮箱 用户名 填你自己的

2. git config --list

## 帮助命令

1. git help

2. git help add

##创建初始化仓库

1. git init  #初始化仓库 生成 .git 文件夹

Initialized empty Git repository in C:/Users/Administrator/Desktop/git_test/.git/

2. 查看当前仓库状态命令

   git status

   

3. 追踪文件命令

   git add 【参数】

   git add a.py

   git add .  最常用的。 把所有的文件 add 进去

   git rm --cached a.py  #放弃追踪

4. 版本生成命令

   git commit

   git commit -m "v1"   # 单词 modify 修改

## 日志命令

    1. git log  完整的日志

    2. git log --oneline 打印一行

    3. git log --graph 查看版本线图

    4. git log --all 打印所有分支的日志

    5. git reflog  打印版本回退的日志

## 文件对比命令

    1. git diff 对比 没有 add (staged) 的文件

    2. git diff --staged  对比 add (staged) 的文件

## 版本回退命令

    1. git reset --hard [hash]  #哈希值

    2. git reset --hard HEAD^^ 回退到前一个版本

        ------不建议使用

## 回到旧版本命令

    1. git checkout [hash] -- .

    2. git checkout [hash] -- [filename]

   

## 文件忽略

 创建 .gitignore 文件,把需要忽略的文件名写入 .gitignore 文件中

  例子:

.gitignore

  /node_modules

  *.log

  *.zip

  a.py

--------注意,要先写入.gitignore先让.gitignore文件忽略

## 分支 branch

1. git branch # 查看分支

2. git checkout [branch name]  # 切到某分支

3. git checkout -b [branch name] # 创建某分支,并切换过去

4. git branch [branch name] -d保护性 有改动,但没有merge 不能删

5. git branch [branch name] -D 强删

6. 分支的理解:

    1。分支之间是互不影响的

    2。分支可以合并 merge

    3。 master 合并 dev 需要站在 master 分支上 (注意合并的顺序)

    4。分支冲突的解决:

        1. 尽量和同事沟通好,能最大限度的避免冲突

        2. 如果冲突不确定, 我们可以用 git merge --abort 取消合并

        3. 有冲突的话,和同事沟通,确定好最终的代码,然后提交

## 远端仓库

    1.Git global setup 全局设置

    设置用户名和邮箱

    2.  git config --global user.name "Kervin Chen"

        git config --global user.email "carboo@163.com"

    3. 进入本地目录

        cd existing_folder

    4. 初始化仓库

        git init

    5. 设置 git remote

    git remote add origin git@gitlab.example.com:Kervin/dsafdsf.git

    6. git add .

    7. git commit -m "init version"

    8. git push -u origin master

    9. git remote set-url origin [new url]

    10. git push --all

    11. git pull 从远端拉取分支。 git pull === git fetch + git merge

    12. git fetch origin master:temp  # 从远端获取 master 分支, 本地创建 temp分支,把数据放到temp 分支  然后就可以进行合并 合并之前一定要知道你在哪个分支上 比如站在 master上 合并 temp   =》 git merge temp

     git clone -b

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值