在mac OS-X Mavericks上,尝试在已装载的卷上创建一个repo的本地克隆。
我创建了原始存储库
pushd /Volumes/somevolume
mkdir testbox
cd testbox
git init
我在其中添加,提交并提交文件
cat > test.text
testing git remote
^D
git add -A
git commit -am "initial commit"
我现在将回购克隆克隆到我的常住家
pushd ~/Documents
git clone /Volumes/somevolume/testbox
cd testbox
cat test.text
一切都好。现在我在我的本地克隆
中更改并提交文件cat >> test.text
a new line
^D
git commit -am "add a new line to test.text"
检查它是否真的发生了变化
cat test.text
testing git remote
a new line
并将其推送到远程原点
git push origin master
编辑:我收到警告,我不明白
Counting objects: 5, done.
Writing objects: 100% (3/3), 277 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: warning: updating the current branch
To /Volumes/lockbox/testbox/
bb6f7d1..5d2f521 master -> master
我现在去检查文件是否被推送
pushd /Volumes/somevolume/testbox
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: test.text
#
好吧,这很奇怪......让我们看看文件是否包含我认为我推的内容......
cat test.text
testing git remote
我尝试添加和推送的新行不在这里,即使git认为文件被修改了?从本地工作目录推送后,为什么我必须在origin远程执行任何操作? Github似乎没有这样的工作方式。也许这些变化在某处
git diff
无法看到任何变化。我现在完全糊涂了。
答案 0 :(得分:1)
当您push
到非bare远程存储库时,您的更改会记录到.git
目录中的存储库中,但不会应用于签出版本的存储库(“工作副本”)。这就是为什么通常建议只使用裸存储库作为遥控器,因为否则行为可能会令人困惑。
您会注意到,推送后,您的原始存储库显示文件test.txt
已被修改:
pushd /Volumes/somevolume/testbox
git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: test.text
这是因为该文件现在与存储库的内容不同。
警告“remote:warning:updated the current branch”警告您正在推送到当前已检出的分支。
有时您可能真的想要推送到非裸存储库(可能您正在部署具有git push
或其他内容的网站),但您需要设置适当的机制来应用更新工作副本(通常需要将工作副本视为只读,以避免冲突)。