English 中文(简体)
检查当地邮局有一切承诺,并推向主人
原标题:Check that the local git repo has everything committed and pushed to master
  • 时间:2012-01-12 06:05:50
  •  标签:
  • git

I have some shell script where I want to check one of my git repos. I want to know if that repos has everything committed and if it is pushed to master. Before this test I make git fetch to make sure I have the latest changes.

我已经找到了办法,以核实重新邮袋是否有一些未商定的变化:

if ! git --work-tree=$HOME/git/project --git-dir=$HOME/git/project/.git diff-index --quiet HEAD --; then
    echo "Has some changes";
fi

But this is not the only thing I need. I also want to make sure that all my local commits are pushed to master.

这样做的最容易的方法是什么?

最佳回答

From Mark Longair s great answer I understood that is is possible to check that local git repo has everything commited and pushed but you need to run several commands to do so.

I ve written a small script that does all that and write in a frienly way what has happened.

$ is_git_synced ~/git/* --only_errors
Error: path  /home/bessarabov/git/Dancer  has staged changes
Error: path  /home/bessarabov/git/Ubic  has some divergences with remote  origin 

And you can also use exit code to find out if everything is commited and pushed or not.

https://github.com/bessarabov/App-IsGitSynced”rel=“nofollow”https://github.com/bessarabov/App-IsGitSynced和CPAN:

问题回答

简单地说,这样做非常容易。

gitzan -n

(“n”对于“dry-run”来说是不足的,这意味着,它不去做推动,而是将告诉你它会推动什么)

如果说“随时更新”的话,那么你就会把一切都推向来。

否则,它将给你一份清单,列出尚未被推向原状的所有承诺。

或者,如果你们的原产地有变化,那么,它可能会抱怨可能由于推移而出现合并(这重复了“一些变化”检查你已经做的重新检查)。

You can check that everything is committed with:

git diff --exit-code && git diff --cached --exit-code

In a typical configuration, on a successful push to a master in origin, the remote-tracking branch origin/master will be updated. So, to check if you ve pushed all your changes, you can test if:

git rev-parse --verify master

......

git rev-parse --verify origin/master

After a git fetch, to check if there are local commits in your branch that have not been pushed to a remote, try this:

git diff --exit-code <remote>/<branch>..<branch>

这还将告诉你,如果在遥远的地方有人承诺,你在当地没有。 请注意,这只是检查变化,因此,如果在偏远和地方分局有相同变化,那么这一指挥可能不会发现这一点。 在一份文字中,我通常将这一条推到<条码>/dev/null,只是检查返回状况。 因此,假定您的距离为origin,而贵方的分支为master/code>,指挥部门将照此办理:

git diff --exit-code origin/master..master > /dev/null

As others have suggested, I also use git diff --exit-code and git diff --cached --exit-code to check for local uncommitted changes.





相关问题
git confusion - cloning a repo is returning a past version

Im having some confusion with my git usage. I cloned a repo from one comp to the other, and the new clone is the state of the original that was active some time ago. So its cloning a past version. ...

Appropriate strategy for tagging and hotfixing with git

I was wondering if the strategy I m using for tagging and hotfixing tags (which then I use for deploying rails applications) with git is appropriate. For tagging I just tag a commit of the master ...

Tips on upgrading CVS to git/hg?

We still use CVS, I use git and hg for my personal use though I m still a novice at both, but I realize they re much more modern and better, faster, distributed, etc. It s just everyone is so ...

Using Git in a TFS shop

Using Git at home has spoiled me - I now find using TFS at work to be a bit of a drag and want to explore the possibility of using Git locally and syncing somehow with TFS. I figure there are a few ...