V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ylcx123
V2EX  ›  程序员

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

  •  
  •   ylcx123 · 2015-09-15 00:39:01 +08:00 · 3935 次点击
    这是一个创建于 3138 天前的主题,其中的信息可能已经有所发展或是发生改变。
    1. 项目是用 SVN 管理的,但是我为了使用本地临时提交,用了 git 来管理本地提交。
    2. 我有个坏习惯,遇到项目出问题时(非代码问题),我会删除项目文件夹,重新从 SVN checkout 出来。这也就导致项目文件夹里的.git 文件夹被删除了。
    3. 这事发生过两次。所以想有没有 git 本地远程仓库?就是把某个其他位置的文件夹设为远程仓库?
    14 条回复    2015-09-15 11:29:50 +08:00
    dorentus
        1
    dorentus  
       2015-09-15 00:41:35 +08:00 via iPhone
    可以 关键字 bare repo

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

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

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

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

    估计与 SVN 和 git 混用有关

    PS:SVN 排除了.git 文件夹,但是 git 添加了.svn 文件夹。
    ylcx123
        13
    ylcx123  
    OP
       2015-09-15 10:49:43 +08:00
    @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
       2015-09-15 11:29:50 +08:00
    @ylcx123
    原来是这样写: git remote add origin file:///E://abc//myproj.git
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5721 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 01:43 · PVG 09:43 · LAX 18:43 · JFK 21:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.