2011-03-01 49 views
1

我想了解如何git的作品。所以我初始化一个空的回购,并添加一个文件,如下所示。如何在以下情况下获取更改?

cd /home/adnan/workspace 
mkdir git-test 
cd git-test 
git init 
touch README 
git add . 
git commit -m "initial commit" 

现在,我使用下面的命令序列

cd /home/adnan/Desktop 
git clone /home/adnan/workspace/git-test 

之后,我做了修改README文件,承诺并把它们推到了第一回购使用以下命令

克隆它这个回购
cd /home/adnan/Desktop/git-test 
vi README 
git commit -a -m "second commit" 
git push 

现在运行git log在这两个回购显示相同的东西,即

提交 cdf192f7e26e734c7a56cc830ade2e2d13c6fb0d 作者:阿德南·瓦希德· 日期:
周二3月1日14点05分12秒2011 0500

second commit 

提交 f8b75838e728e46cae949f66ff86d29c0864d976 作者:阿德南·瓦希德· 日期:
星期二Mar 1 14:03:23 2011 +0500

initial commit 

但我不知道如何得到原始回购协议的变化,例如/home/adnan/workspace/git-test。如果我尝试做git的结帐,我得到这个消息:

M README 

我如何,我在克隆的回购做出加推的变化?

回答

1

当您完成git push时,您是否看到错误信息?像这样(假设git>1.7.0)?

$ git push 
Counting objects: 5, done. 
Writing objects: 100% (3/3), 246 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
remote: error: refusing to update checked out branch: refs/heads/master 
remote: error: By default, updating the current branch in a non-bare repository 
remote: error: is denied, because it will make the index and work tree inconsistent 
remote: error: with what you pushed, and will require 'git reset --hard' to match 
remote: error: the work tree to HEAD. 
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to 
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into 
remote: error: its current branch; however, this is not recommended unless you 
remote: error: arranged to update its work tree to match what you pushed in some 
remote: error: other way. 
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set 
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. 
To /home/pfarmer/git-test/git-test 
! [remote rejected] master -> master (branch is currently checked out) 
error: failed to push some refs to '/home/pfarmer/git-test/git-test' 

基本上默认情况下,您不能推送到非裸仓库。但是你可以做的是git pull,所以尝试:

cd /home/adnan/workspace/git-test 
git pull /home/adnan/Desktop/git-test 

,你应该看到:

$ git pull ../git-test2/ 
From ../git-test2 
* branch   HEAD  -> FETCH_HEAD 
Updating 161aeea..c66b221 
Fast-forward 
README | 1 + 
1 files changed, 1 insertions(+), 0 deletions(-) 
+0

没有,我没有看到任何错误。推动是成功的。当我在原始回购上做'git log'时,我知道这一点,它显示第二次提交。我只是无法检查变化。 – binW 2011-03-01 10:04:23

+1

好吧,所以你使用的是git <1.7.0,当你在'/ home/adnan/workspace/git-test'中做'git log'时会看到什么 – 2011-03-01 10:13:03

+3

@binW:我怀疑'git reset - 硬推“存储库会让你想要成为你想要的位置,但这是一个糟糕的工作流程 - 你应该像彼得所说的那样拉动你。除非你真的知道你在做什么,否则你应该只推送到裸仓库。 – Cascabel 2011-03-01 13:56:02

相关问题