zoukankan      html  css  js  c++  java
  • git 本地与服务器的同步

    如果在服务器上直接用 git init
    则会自动在当前目录创建.git目录
    但在本地clone后修改后,不能push,
    这是由于git默认拒绝了push操作,需要进行设置,修改.git/config添加如下代码:

    [receive]
    denyCurrentBranch = ignore

    在初始化远程仓库时最好使用 git --bare init

    需首先手工创建.git目录,进入.git目录后再执行此命令

    本地克隆服务器的命令
    git clone username@host:/path/to/directory/.git


    push后服务器目录里没有反应,这时可以在working directory使用

    git reset --hard

    才能看到push后的内容。

    如果执行此命令出现错误
    fatal: This operation must be run in a work tree

    可以在服务器上先执行一下
    git config core.bare false
    执行完此命令,则本地不能再push到服务端,如若需要再次push 则执行一下
    git config core.bare true

    可以把以下命令做成脚本,每次push后执行即可实现服务器与本地的文件同步:


    git config core.bare false
    git reset --hard
    git config core.bare true

  • 相关阅读:
    JAVA_SE基础——35.static修饰成员函数
    Mybatis环境搭建
    搭建Mybatis环境遇到的问题
    Windows10系统下,彻底删除卸载MySQL
    StringBuffer类append方法的用法和用途
    Listener监听器
    Filter过滤器
    JSTL
    EL表达式
    JSP
  • 原文地址:https://www.cnblogs.com/meetrice/p/3530996.html
Copyright © 2011-2022 走看看