zoukankan      html  css  js  c++  java
  • Git命令回顾

    团队从Eclipse迁移到Android Studio之后,也从SVN迁移到Git了。

    一直忙于需求迭代无暇做迁移,现在才开始做,相见恨晚,好东西,高大上,词穷。

    回顾和记录一下git的一些基本操作。下面完成这样一个流程:

    远程机器创建git仓库 --> 本地机器创建git仓库 -->从本地仓库推代码到远程仓库 --> 从远程仓库把代码clone到本地新的仓库。

    //先查看git装了没有
    [user@remotemachine /]# git
    
    //设置全局参数
    [user@remotemachine /]# git config --global user.name "User"
    [user@remotemachine /]# git config --global user.email "xxx@xxx.com"
    
    //创建一个目录
    [user@remotemachine /]# mkdir Git001
    
    //进入目录
    [user@remotemachine /]# cd Git001/
    
    //初始化为一个git仓库,这里有坑
    [user@remotemachine Git001]# git init
    Initialized empty Git repository in /Git001/.git/
    
    //用上面的方式创建的仓库是一个non-bare的仓库,是无法push本地仓库到这个non-bare仓库的,可参考bare and non-bare.
    
    //所以要初始化一个bare的git仓库作为远程仓库
    [user@remotemachine Git002]# git init --bare
    Initialized empty Git repository in /Git002/
    //查看一下(可带着-ah查看)
    [user@remotemachine SwiftLearning]# ls
    branches  config  description  HEAD  hooks  info  objects  refs
    
    到现在远程git仓库就创建好了,下面来创建本地仓库并push到这个远程仓库。
    
    //初始化git,这里就不用bare了
    LocalMachine:GitA viyu$ git init
    Initialized empty Git repository in /xxx/.git/
    
    //查看git仓库的状态
    LocalMachine:GitA viyu$ git status
    On branch master
    Initial commit
    Untracked files:
    (use "git add <file>..." to include in what will be committed)
    Swift002.playground/
    [...省略]
    nothing added to commit but untracked files present (use "git add" to track)
    
    //添加一个文件到本地仓库
    LocalMachine:GitA viyu$ git add swift001.playground/
    
    //添加所有文件到本地仓库
    LocalMachine:GitA viyu$ git add .
    
    //再次查看git状态
    LocalMachine:GitA viyu$ git status
    On branch master
    Initial commit
    Changes to be committed:
    (use "git rm --cached <file>..." to unstage)
    new file:   Swift002.playground/Contents.swift
    [....省略]
    
    //提交到本地仓库,不亏是分布式仓库,这就提交了 
    LocalMachine:GitA viyu$ git commit -m "add all learning file to git"
    20 files changed, 377 insertions(+)  
    
    //再次查看git状态
    LocalMachine:GitA viyu$ git status
    On branch master
    nothing to commit, working directory clean
    
    //push本地仓库到上面建立的远程仓库,先链接
    LocalMachine:GitA viyu$ git remote add origin ssh://user@remotemachine/Git002
    
    fatal: remote origin already exists.
    //假如报上面这个错误,origin已经存在了,要么另起一个名字,要么更新之:
    LocalMachine:GitA viyu$ git remote set-url origin ssh://user@remotemachine/Git002
    
    //再推送
    LocalMachine:GitA viyu$ git push origin master 
    
    现在已经把本地仓库推送到远程仓库了,下面再从远程仓库clone下来到一个新的本地仓库
    
    //先初始化
    ViyudeMacBook-Pro:gittest viyu$ git init
    
    //再克隆
    ViyudeMacBook-Pro:gittest viyu$ git clone ssh://user@remotemachine/Git002
    
    //查看状态
    ViyudeMacBook-Pro:gittest viyu$ git status
    
    //查看总共几个分支
    ViyudeMacBook-Pro:gittest viyu$ git branch
    * master
    
    待续...
  • 相关阅读:
    Python 极简教程(十)集合 set
    Python 极简教程(九)元组 tuple
    Python 极简教程(七)列表 list
    Python 极简教程(八)字符串 str
    DevOps实践之一:基于Docker构建企业Jenkins CI平台
    kubernetes实践之一:kubernetes二进制包安装
    Linux挖矿病毒 khugepageds详细解决步骤
    kubernetes实践之五:深入理解Service及内部DNS搭建
    kubernetes实践之四:深入理解控制器(workload)
    kubernetes实践之三:深入理解Pod对象
  • 原文地址:https://www.cnblogs.com/mosthink/p/5289119.html
Copyright © 2011-2022 走看看