Mic*_*tum 12 git version-control
我经常需要在路上开发东西,没有互联网/网络连接.我只是一个开发人员,所以直到现在我只是在我的机器上有一个SVN存储库,并在我离开时在我的笔记本电脑上结账.问题:这让我在路上没有源控制.
所以我尝试改为git,这似乎做了我想要的,但我不确定我是否理解它应该如何在我的设置中使用.
实质上:
git initgit clonegit clonegit commit用于提交对本地存储库的任何更改git push将所有更改推送回\ myserver\share\prohectgit pull在机器1上摆脱\ MYSERVER \共享\项目的最新变化这可行,但该git push命令给我一个警告说,不支持推出签出分支,因为它可能会混淆索引.现在,我很困惑,因为消息也是用严肃的语气写的,这意味着我应该尊重它(事实上,gitk显示我现在有两个分支:master和remotes/origin/master),但是我尚未完全理解术语.
在我的情况下,正确的步骤是什么?
编辑:有两个奇怪的地方.第一个是如果我只是更改文件,它会显示"已更改但未更新".这很奇怪:
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: myproject/Readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
第二个消息是我认为是罪魁祸首,git push的输出:
warning: You did not specify any refspecs to push, and the current remote
warning: has not configured any push refspecs. The default action in this
warning: case is to push all matching refspecs, that is, all branches
warning: that exist both locally and remotely will be updated. This may
warning: not necessarily be what you want to happen.
warning:
warning: You can specify what action you want to take in this case, and
warning: avoid seeing this message again, by configuring 'push.default' to:
warning: 'nothing' : Do not push anything
warning: 'matching' : Push all matching branches (default)
warning: 'tracking' : Push the current branch to whatever it is tracking
warning: 'current' : Push the current branch
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 333 bytes, done.
Total 4 (delta 3), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done.
warning: updating the current branch
warning: Updating the currently checked out branch may cause confusion,
warning: as the index and work tree do not reflect changes that are in HEAD.
warning: As a result, you may see the changes you just pushed into it
warning: reverted when you run 'git diff' over there, and you may want
warning: to run 'git reset --hard' before starting to work to recover.
warning:
warning: You can set 'receive.denyCurrentBranch' configuration variable to
warning: 'refuse' in the remote repository to forbid pushing into its
warning: current branch.
warning: To allow pushing into the current branch, you can set it to 'ignore';
warning: but this is not recommended unless you arranged to update its work
warning: tree to match what you pushed in some other way.
warning:
warning: To squelch this message, you can set it to 'warn'.
warning:
warning: Note that the default will change in a future version of git
warning: to refuse updating the current branch unless you have the
warning: configuration variable set to either 'ignore' or 'warn'.
To file:///\\myserver\share\project
129649b..1f4b957 master -> master
Run Code Online (Sandbox Code Playgroud)
因此它告诉我"不推荐进入当前分支",但我并没有真正了解这样做的正确方法.
jan*_*neb 10
否则看起来不错,但为了避免错误消息,您可以将"上游"存储库设置为空存储库,即不包含已检出副本的存储库.你这样做
git --bare init
Run Code Online (Sandbox Code Playgroud)
参见例如这个例子
该git push命令要求您指定refspec,否则您将必须编辑.git/config以指定在未指定refspecs的情况下的默认操作.例如,考虑具有命名分支的方案master.
要推动master分支,您将:
git push refs/heads/master:refs/heads/master
git push master:master
git push master
Run Code Online (Sandbox Code Playgroud)
以上所有都是一样的.refspec看起来像路径是指定refspec最明确的方式.这样,您可以确定您指的是名为branch的分支master而不是名为的标记master.
否则,您可以编辑.git/config并添加:
[push]
default = matching
Run Code Online (Sandbox Code Playgroud)
这将允许您只是git push,并且Git将推送到您当前所在的本地分支的远程分支.例如,如果您当前在分支中master,git push则将本地主分支推送到远程主分支.
正如janneb所说,你必须使用一个裸存储库,以便在没有警告的情况下推送它.推送到普通(非裸)存储库的问题是,主要所有者(特定的"普通"存储库)不希望添加到他/她的存储库中的更改.那时,如果有人推送到此存储库,并删除分支(或任何其他更改),则所有者将不会期望这样的更改.因此,警告.