对作为git存储库的git clone的更改未被视为包含原始存储库中不存在的新更改

时间:2017-08-02 04:53:10

标签: git

如下面的命令所示,git clone已成功用作git存储库并且已将更改推送到它。但是,git status没有检测到更新的克隆和原始git存储库之间的任何差异 - 为什么?

$ mkdir -p /var/tmp/git_master
$ cd /var/tmp/git_master
$ git clone https://the_repo.com/stuff.git

Cloning into 'stuff'...

~
~
~

$ cd
$ mkdir fooey
$ cd fooey
$ git clone /var/tmp/git_master/stuff

Cloning into 'stuff'...
done.

$ cd stuff/
$ git branch test
$ git checkout test

Switched to branch 'test'

$ touch test.txt

~
~
~
$ git commit -m"initial"
$ git push origin test

Counting objects: 6, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 526 bytes | 0 bytes/s, done.
Total 6 (delta 2), reused 0 (delta 0)
To /var/tmp/git_master/stuff
 * [new branch]      test -> test

$ pushd /var/tmp/git_master/stuff
$ git branch
* master
  test
$ git status

On branch master

Your branch is up-to-date with 'origin/master'.

nothing to commit, working tree clean

$

为什么git status报告/var/tmp/git_master/stuff不包含名为test且不在远程存储库https://the_repo.com/stuff.git中的本地分支?

接受回答的输出git branch -avv

$ git branch -avv
* master                52a921c [origin/master] some message
  test                  39dbcbf some message
  remotes/origin/HEAD   -> origin/master
  remotes/origin/xyz    b5edac5 some message
  remotes/origin/master 52a921c some message

引出另一个问题:如何将/var/tmp/git_master/stuff中的所有更改推送到远程存储库https://the_repo.com/stuff.git? (我相信这个后续问题不需要单独提出,因为它完成了原始问题所解决的问题。)

可以在https://stackoverflow.com/a/6232535/1823664 - git checkout test后跟git push -u找到后续问题的解决方案。还有一些人嘲笑过这样的建议:https://stackoverflow.com/a/21232996/1823664

1 个答案:

答案 0 :(得分:2)

  

为什么git status报告/var/tmp/git_master/stuff不包含名为test且不在远程存储库https://the_repo.com/stuff.git中的本地分支?

要确切地看到这一点,请输入:

git branch -avv

您会看到test未与任何远程跟踪分支相关联 与master相对,与origin/master相关联。