• 请不要在回答技术问题时复制粘贴 AI 生成的内容
ylcx123
V2EX  ›  程序员

git 能设置本机某个位置为远程仓库吗?

  •  
  •   ylcx123 · Sep 15, 2015 · 4771 views
    This topic created in 3983 days ago, the information mentioned may be changed or developed.
    1. 项目是用 SVN 管理的,但是我为了使用本地临时提交,用了 git 来管理本地提交。
    2. 我有个坏习惯,遇到项目出问题时(非代码问题),我会删除项目文件夹,重新从 SVN checkout 出来。这也就导致项目文件夹里的.git 文件夹被删除了。
    3. 这事发生过两次。所以想有没有 git 本地远程仓库?就是把某个其他位置的文件夹设为远程仓库?
    14 replies    2015-09-15 11:29:50 +08:00
    dorentus
        1
    dorentus  
       Sep 15, 2015 via iPhone
    可以 关键字 bare repo

    另外,最好改掉这个习惯
    FrankFang128
        2
    FrankFang128  
       Sep 15, 2015 via Android
    顶一楼,改习惯就好了
    ShadowStar
        3
    ShadowStar  
       Sep 15, 2015 via iPad
    file:///Path/to/gitrepo
    或者有个脚本 git-new-workdir ,大概这个名字。
    msg7086
        4
    msg7086  
       Sep 15, 2015   ❤️ 1
    1. 可以,直接指定就好了。是不是 bare 无所谓。就算是 working directory 也可以再次 clone 的。
    2. 改掉这个坏习惯。
    cxbig
        5
    cxbig  
       Sep 15, 2015
    可以,本地文件夹 A 克隆远程 repo ,本地文件夹 B 克隆本地文件夹 A ,用 B 文件夹做工作目录
    如楼上所说,坏习惯要改。 git checkout -f 足够清理干净了。
    582033
        6
    582033  
       Sep 15, 2015 via Android
    出问题个人做法是切一个新分支,然后后退几个版本重新 rebase.
    letterJump
        7
    letterJump  
       Sep 15, 2015
    本地直接同步目录备份就可以了
    chinawrj
        8
    chinawrj  
       Sep 15, 2015
    git init --bare 好啦
    ljbha007
        9
    ljbha007  
       Sep 15, 2015
    git init --bare

    然后到别处
    git clone /path/to/my/git

    提交的时候 git add -A&git commit

    git push
    ljbha007
        10
    ljbha007  
       Sep 15, 2015
    还有 想回退 直接 git reset --hard . 就行了
    sudoz
        11
    sudoz  
       Sep 15, 2015
    git init --bare <repo-name>
    ylcx123
        12
    ylcx123  
    OP
       Sep 15, 2015
    非简单问题,比如之前遇到过的, SVN 的 cleanup 死循环了,最后下了个 sqlite3 才解决。
    还有 eclipse 项目感叹号等, git reset 都不行。

    估计与 SVN 和 git 混用有关

    PS:SVN 排除了.git 文件夹,但是 git 添加了.svn 文件夹。
    ylcx123
        13
    ylcx123  
    OP
       Sep 15, 2015
    @ljbha007
    如果远程仓库是本机的“ E:\\Git\myproject.git\”呢?
    本地项目在“ D:\\SVN\myproject\”
    如何写: git remote -add orgin E:\\Git\myproject.git 这样吗?
    push 的时候报错:

    $ git push --set-upstream origin master
    fatal: 'E:Gitmyproject.git' does not appear to be a git repository
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.
    ylcx123
        14
    ylcx123  
    OP
       Sep 15, 2015
    @ylcx123
    原来是这样写: git remote add origin file:///E://abc//myproj.git
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5423 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 58ms · UTC 08:04 · PVG 16:04 · LAX 01:04 · JFK 04:04
    ♥ Do have faith in what you're doing.