zoukankan      html  css  js  c++  java
  • git常用命令

    git常用命令

    一、在本地新建仓库
    1.在本地初始化一个git仓库 一定要有readme.md文件
        git init
    2. 查看仓库状态
        git status
    3.添加文件给git管理 
        git add .|filename (所有文件或单独指定) 
        git rm (删除文件)
    4.将项目提交到仓库
        git commit -m '注释' 报crlf错误的时候 git config --global core.autocrlf false
    5.添加远程仓库
        git remote add origin https://github.com/huangtingbb/ljblog.git origin 本地仓库名称
    6.提交到远程仓库
        git push -u origin master master 远程仓库名称 //第一次才加-u参数
    7.更新代码
        git pull 
     
    二、在github上有仓库
    1.复制远程仓库到本地
        git clone url filename 
    2.新建分支
        git checkout -b test
    3.修改
        modify some files
    4.把修改加入stage中
        git add .
    5.提交代码
        git commit -m ‘’
    6.review代码
    7.切换到master分支
        git checkout test 
    8.更新代码
        git pull
    9.切换到test分支
        git checkout test
    10.把master的代码合并到test
        git merge master
    11.把test代码推送到远程库
        git push origin test 
     
    三、切换分支
        git checkout master
     
    四、强制更新远程覆盖本地
        git fetch --all    
        git reset --hard origin/master    
     
    五、回滚 
        git reset [--hard] 版本号 --hard会强制回退,并丢失当前到hard的修改,使用log看不到,但是使用reflog看的到
        git log 查看版本号
        git reflog 查看操作过的命令
     
    六、查看文件的修改历史
        1.git log filename 查看文件的提交历史
        2.git log -p filename 查看文件每次提交的差异
        3.git show 版本号 [filename] 查看某次提交的某个文件的差异
     
    七、单独合并某一次提交
        1.git log 查看提交的的版本号
        2.git checkout master 切换到要合并的分支
        3.git cherry-pick   b640e65d
        4.git push 推送
     
    八、设置远程仓库分支
        git branch --set-upstream-to=origin/dev   分支 dev 设置为跟踪来自 origin 的远程分支 dev
     
    九、合并解决冲突
        git stash //将工作区回复到上次提交的内容,同时备份本地工作区修改,压入git栈中
        git pull //更新代码
        git stash pop //弹出最近一次压入栈中的修改,恢复工作区的内容
  • 相关阅读:
    Longest Common Prefix
    Roman to Integer
    Intger to Roman
    Container With Most Water
    Regular Expression Matching
    atoi
    Rotate List
    54. Search a 2D Matrix && Climbing Stairs (Easy)
    53. Minimum Window Substring
    52. Sort Colors && Combinations
  • 原文地址:https://www.cnblogs.com/jint-php7/p/12800582.html
Copyright © 2011-2022 走看看