2016-12-28 31 views
0

如何知道哪些本地提交不在远程?Git - 查找哪些提交是本地的

By,git log我看到了提交历史记录,但我想要查找最后一次提交是否已经推入服务器或只是本地提交。有没有办法知道,而不去服务器和本地历史匹配?

+3

'git status'有帮助吗? _你的分支在'origin/master'提前1提交._ – Danh

回答

0

最后我得到了一个线索,

git status

On branch dev 
Your branch is ahead of 'origin/dev' by 1 commit. 
    (use "git push" to publish your local commits) 
nothing to commit, working directory clean 

Git的状态也显示数量从远程提前提交您的当前分支。

感谢@Danh发表评论

2

复制上次提交散列,并查看分支列表存在提交。
如果您看到remote/origin/<branch-name>,那么您已推动last commit

$ git fetch 
$ git log         # copy last commit-hash 
$ git branch -a --contains <last-commit-hash> 

# Or, (skip copying commit-hash) 
$ git fetch && git branch -a --contains $(git rev-list -n 1 HEAD) 
+0

你可以直接计算出来而不是复制它:'git fetch && git branch -a --contains $(git rev-list -n 1 HEAD)' –

+0

@丹洛,是的。我已经更新了答案。 –

2

是的,你可以检查git log origin/master..master

如果有输出,则显示日志是您没有推送到远程的。如果没有输出,这意味着您当前的分支与主分支相同。

注意:如果git remote还被别人使用,你最好从原点取回然后再比较。

1

GIT中具有多个快捷键,例如HEAD指当前分支的末端,而@ {上游}指远程分支的头部(或最后被推提交)。这些快捷方式对于使用别名非常有用,例如,所以您不会锁定使用分支名称,如和固定远程名称,如原点

使用git log;

git log @{upstream}..HEAD

我用下面的

git config alias.changes "log --graph --abbrev-commit --decorate --date=relative --pretty=terse @{upstream}...HEAD"

我然后只需使用

git changes

列出在我当前分支未推变化。

注意:如果@ {}上游似乎不工作,要注意-u--set-upstream选项git push。使用git push -u origin master将确保原产地/主人被认为是分支的上游存储库。然后@ {upstream}快捷方式应该正常工作。