Git: How to check if a local repo is up to date?

佐手、 提交于 2019-12-29 10:13:10

问题


I would like to know if my local repo is up to date (and if not, ideally, I would like to see the changes).

How could I check this without doing git fetch or git pull ?


回答1:


Try git fetch --dry-run The manual (git help fetch) says:

--dry-run
Show what would be done, without making any changes.



回答2:


git remote show origin

Result:

HEAD branch: master
  Remote branch:
    master tracked
  Local branch configured for 'git pull':
    master merges with remote master
  Local ref configured for 'git push':
    master pushes to master (local out of date) <-------



回答3:


you can use git status -uno to check if your local branch is up-to-date with the origin one.




回答4:


First use git remote update, to bring your remote refs up to date. Then you can do one of several things, such as:

  1. git status -uno will tell you whether the branch you are tracking is ahead, behind or has diverged. If it says nothing, the local and remote are the same.
  2. git show-branch *master will show you the commits in all of the branches whose names end in 'master' (eg master and origin/master).

If you use -v with git remote update (git remote -v update) you can see which branches got updated, so you don't really need any further commands.




回答5:


Not really - but I don't see how git fetch would hurt as it won't change any of your local branches.




回答6:


Another alternative is to view the status of the remote branch using git show-branch remote/branch to use it as a comparison you could see git show-branch *branch to see the branch in all remotes as well as your repository! check out this answer for more https://stackoverflow.com/a/3278427/2711378




回答7:


You'll need to issue two commands:

  1. git fetch origin
  2. git status



回答8:


You must run git fetch before you can compare your local repository against the files on your remote server.

This command only updates your remote tracking branches and will not affect your worktree until you call git merge or git pull.

To see the difference between your local branch and your remote tracking branch once you've fetched you can use git diff or git cherry as explained here.




回答9:


If you use

git fetch --dry-run -v <link/to/remote/git/repo>

you'll get feedback about whether it is up-to-date. So basically, you just need to add the "verbose" option to the answer given before.




回答10:


This is impossible. How can you know whether or not the repository is "up-to-date" without going to the remote repository to see what "up-to-date" even means?



来源:https://stackoverflow.com/questions/7938723/git-how-to-check-if-a-local-repo-is-up-to-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!