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

    git提交代码:

    [root@localhost git]# git add bash             #添加bash文件
    [root@localhost git]# git commit -m "bash"     # -m 表示提交的注释
    [slave 27b1758] bash
    1 file changed, 1 insertion(+)
    create mode 100644 bash

    [root@localhost git]# git remote add monmon 192.168.25.133:/root/git            #
    [root@localhost git]# git push monmon
    Counting objects: 3, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 287 bytes | 0 bytes/s, done.
    Total 2 (delta 0), reused 0 (delta 0)
    To 192.168.25.133:/root/git
    2b19488..27b1758 slave -> slave

    分支:

    [root@localhost git]# git branch       #查看当前所属分支

    master
    * slave

    [root@localhost git]# git branch     #添加分支
    * master
    test

    [root@localhost git]# git branch -d test        #-d 删除分支
    Deleted branch test (was 6b6c8fa).

    [root@localhost git]# git checkout test     #切换分支
    Switched to branch 'test'

    [root@localhost git]# git branch -r        #查看远程分支与本地分支的链接
    master/master
    master/slave
    [root@localhost git]# git branch -a      #查看所有远程分支
    master
    * slave
    remotes/master/master
    remotes/master/slave

    [root@localhost ~]# git clone 192.168.25.133:/root/git/slave          #默认clone的是master分支

    [root@localhost ~]# git clone -b slave 192.168.25.133:/root/git/slave    #指定克隆slave分支

    取回origin主机的next分支,与本地的master分支合并,需要写成下面这样 

    [root@localhost ~]# git pull origin next:master

     

    合并分支到现在所在的分支上(不同的文件内容会合并)

    [root@localhost git]# git merge test

     

    git push origin local_branch:remote_branch  语法

    [root@localhost git]# git push 192.168.25.133:/data/git/ fenzhong1:fenzhong1     #推送本地分支到远程分支
    Total 0 (delta 0), reused 0 (delta 0)
    To 192.168.25.133:/data/git/
    * [new branch] fenzhong1 -> fenzhong1

    删除代码:

    一般情况下,你通常直接在文件管理器中把没用的文件删了,或者用rm命令删了:

    $ rm test.txt
    

    这个时候,Git知道你删除了文件,因此,工作区和版本库就不一致了,git status命令会立刻告诉你哪些文件被删除了:

    [root@localhost git]# git status
    
        deleted:    test.txt

    现在你有两个选择,一是确实要从版本库中删除该文件,那就用命令git rm删掉,并且git commit

    $ git rm test.txt
    rm 'test.txt'
    
    $ git commit -m "remove test.txt"
    [master d46f35e] remove test.txt
     1 file changed, 1 deletion(-)
     delete mode 100644 test.txt
    

    现在,文件就从版本库中被删除了。

    另一种情况是删错了,因为版本库里还有呢,所以可以很轻松地把误删的文件恢复到最新版本:

    [root@localhost git]# git status
    # deleted: slave

    [root@localhost git]# git checkout --  slave

    git checkout其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”

    git push 出现warning:

    [root@localhost gut]# git push test
    warning: push.default is unset; its implicit value is changing in
    Git 2.0 from 'matching' to 'simple'. To squelch this message
    and maintain the current behavior after the default changes, use:

    git config --global push.default matching

    To squelch this message and adopt the new behavior now, use:

    git config --global push.default simple

    解决方法:

    [root@localhost gut]# git config --global push.default matching 

    git push第一次报错

    原因:

    本地没有update到最新版本的项目(git上有README.md文件没下载下来)

    本地直接push所以会出错。

    解决方法:

    git pull --rebase origin master

  • 相关阅读:
    python快速查看内置模块函数
    kettle -小技巧 null 跳过唯一索引
    IOException:Connection refused:connect Kettle连接数据库
    各种数据库的jdbc驱动下载及连接方式
    DataCleaner中文文档
    ModuleNotFoundError: No module named 'xlwt' 。
    liunx 常用命令
    Mysql 环境搭建详解
    查询mysql所有表数据、字段信息
    mysqp pk、nn、qu、b、un、zf、ai、g代表的意思
  • 原文地址:https://www.cnblogs.com/byfboke/p/9199012.html
Copyright © 2011-2022 走看看