我已经克隆了一个 github 存储库并且在本地没有进行任何更改。Github 存储库在同一分支上进行了提交。
这个例子可能对某人有帮助:
注意“ origin”是我的远程“Github 上的内容”的别名 注意“ mybranch”是我正在与 github 同步的分支“本地内容”的别名 ——如果你没有创建,你的分支名称是 ‘master’一。但是,我使用不同的名称mybranch来显示使用分支名称参数的位置。
origin
mybranch
我在 github 上的远程仓库到底是什么?
$ git remote -v origin https://github.com/flipmcf/Playground.git (fetch) origin https://github.com/flipmcf/Playground.git (push)
添加“相同代码的其他 github 存储库”——我们称之为 fork:
$ git remote add someOtherRepo https://github.com/otherUser/Playground.git $git remote -v origin https://github.com/flipmcf/Playground.git (fetch) origin https://github.com/flipmcf/Playground.git (push) someOtherRepo https://github.com/otherUser/Playground.git (push) someOtherRepo https://github.com/otherUser/Playground.git (fetch)
确保我们的本地仓库是最新的:
$ git fetch
在本地更改一些内容。假设文件 ./foo/bar.py
$ git status # On branch mybranch # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: foo/bar.py
查看我未提交的更改
$ git diff mybranch diff --git a/playground/foo/bar.py b/playground/foo/bar.py index b4fb1be..516323b 100655 --- a/playground/foo/bar.py +++ b/playground/foo/bar.py @@ -1,27 +1,29 @@ - This line is wrong + This line is fixed now - yea! + And I added this line too.
在本地提交。
$ git commit foo/bar.py -m"I changed stuff" [myfork 9f31ff7] I changed stuff 1 files changed, 2 insertions(+), 1 deletions(-)
现在,我和我的遥控器不同(在 github 上)
$ git status # On branch mybranch # Your branch is ahead of 'origin/mybranch' by 1 commit. # nothing to commit (working directory clean)
与远程区别 - 你的叉子:(这经常用git diff master origin)
git diff master origin
$ git diff mybranch origin diff --git a/playground/foo/bar.py b/playground/foo/bar.py index 516323b..b4fb1be 100655 --- a/playground/foo/bar.py +++ b/playground/foo/bar.py @@ -1,27 +1,29 @@ - This line is wrong + This line is fixed now - yea! + And I added this line too.
(git push 将这些应用到远程)
我的远程分支与远程主分支有何不同?
$ git diff origin/mybranch origin/master
我的本地内容与远程 master 分支有何不同?
$ git diff origin/master
我的东西与其他人的 fork,同一个 repo 的 master 分支有何不同?
$git diff mybranch someOtherRepo/master