zoukankan      html  css  js  c++  java
  • Git 基本命令

    Git 基本命令

    基本使用

    生成公钥ssh-keygen

    1. ssh-keygen -t rsa -C "youremailaddress@hotmail.com"
    2. 打开相关文件夹,一般在 C:UsersAdministrator.sshid_rsa.pub,复制
    3. 打开gitlab, 设置 -> ssh密钥,将上一步的密钥添加至此,选择添加密钥

    本地仓库

    1. 初始化本地仓库: git init

    拉取远端项目 git clone

    1. 拉取远端项目 git clone remote-address@gitlab.com
    2. 拉取指定分支项目 git clone -b prod remote-address@gitlab.com

    增加删除修改操作

    1. 新增所有改动 git add .
    2. 新增单个文件 git add [file]
    3. 删除工作区文件,并且将该次删除放入暂存区: git rm
    4. 停止追踪指定文件,但该文件会保留在工作区: git rm --cached [file]
    5. 改名文件,并且将这个改名放入暂存区: git mv [file-original] [file-renamed]

    撤销操作:

    1. 恢复暂存区的指定文件: git checkout -- [file]
    2. 恢复某个commit的指定文件到暂存区和工作区: git checkout commit [file]
    3. 恢复暂存区的所有文件到工作区: git checkout -- .
    4. 重置暂存区的指定文件,与上一次commit保持一致,但工作区不变: git reset [file]
    5. 重置当前分支的指针为指定commit,同时重置暂存区,但工作区不变: git reset [commit]
    6. 重置暂存区与工作区,与上一次commit保持一致: git reset --hard
    7. 重置当前分支的HEAD为指定commit,同时重置暂存区和工作区,与指定commit一致: git reset --hard [commit]
    8. 暂时将未提交的变化移除: git stash
    9. 将暂存的未提交的变化移入: git stash pop

    提交操作:

    1. 提交暂存区到仓库区: git commit -m [message]
    2. 提交暂存区的指定文件到仓库区: git commit [file1] [file2] ... -m [message]
    3. 重做上一次commit,并包括指定文件的新变化: git commit --amend [file1] [file2] ...

    分支操作:

    1. 列出所有本地分支: git branch
    2. 列出所有远程分支: git branch -r
    3. 列出所有本地分支和远程分支: git branch -a
    4. 新建一个分支,但依然停留在当前分支: git branch [branch-name]
    5. 新建一个分支,并切换到该分支: git checkout -b [branch]
    6. 新建一个分支,指向指定commit: git branch [branch] [commit]
    7. 新建一个分支,与指定的远程分支建立追踪关系: git branch --track [branch] [remote-branch]
    8. 切换到指定分支,并更新工作区: git checkout [branch-name]
    9. 合并指定分支到当前分支: git merge [branch]
    10. 选择一个commit,合并进当前分支: git cherry-pick [commit]
    11. 删除分支: git branch -d [branch-name]
    12. 删除远程分支: git push origin --delete [branch-name]

    tag操作:

    1. 列出所有tag: git tag
    2. 新建一个tag在当前commit: git tag [tag]
    3. 新建一个tag在指定commit: git tag [tag] [commit]
    4. 删除本地tag: git tag -d [tag]
    5. 删除远程tag: git push [remote] :refs/tags/[tagName]
    6. 提交指定tag: git push [remote] [tag]
    7. 提交所有tag: git push [remote] --tags
    8. 新建一个分支,指向某个tag: git checkout -b [branch] [tag]

    查看信息操作:

    1. 显示有变更的文件: git status
    2. 显示当前分支的版本历史: git log

    远程同步:

    1. 下载远程仓库的所有变动: git fetch [remote] [branch]
    2. 显示所有远程仓库: git remote -v
    3. 增加一个新的远程仓库,并命名: git remote add [shortname] [url]
    4. 取回远程仓库的变化,并与本地分支合并: git pull [remote] [branch]
    5. 上传本地指定分支到远程仓库: git push [remote] [branch]
    6. 推送所有分支到远程仓库: git push [remote] --all

    打包操作:

    1. 生成一个可供发布的压缩包: git archive


    作者:开源NetCore
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

     
  • 相关阅读:
    React 之使用 fetch
    react-native 环境搭建
    create-react-app 配置 less
    React新的前端思维方式
    字体图标 —— IconMoon
    你不知道的javascript 之 >>
    前端的自我修养
    jquery 学习
    html的meta总结
    git基本操作 nginx基本操作
  • 原文地址:https://www.cnblogs.com/Zenderblogs/p/14783030.html
Copyright © 2011-2022 走看看