1

ローカルで変更を確認する方法を知っています:
Get changes before commit :

git diff master

コミット後&&プッシュ前に変更を取得:

git diff origin/master
or
git diff remotes/origin/master 

私が欲しいのは:

  1. リモート サーバーから最新バージョンを git clone します。たとえば、ローカル バージョンはv1です。
  2. リモート サーバーを別の側から変更します。たとえば、リモート バージョンはv2です (ローカル バージョンはまだ v1 です) 。
  3. リモートサーバーとの違いを取得

そして、次の手順でリモートサーバーの変更を取得する方法を知っています:

git remote foo git@github.com:user/foo.git
git fetch foo
git diff master foo/master

ただし、次のように、リモートサーバーの変更を確認するために 1 つのコマンドにエイリアスを設定したいと考えています。

git rdiff master
or something else

1 つのコメントでリモート サーバーの変更を取得することは可能ですか? ありがとう。


ところで、ローカルリポジトリにオリジン取得されているのを見つけたのですが、再度取得せずに使用するにはどうすればよいでしょうか?

$ git remote -v
origin  git@github.com:Marslo/VimConfig.git (fetch)
origin  git@github.com:Marslo/VimConfig.git (push)
4

2 に答える 2

1

First of all, there is a logical problem with this:

git rdiff master

Which remote are you going to compare against? So in the very list, it should be something like:

git rdiff remote_name branch_name

which should expand to:

git fetch remote_name && git diff remote_name/branch_name

You can create exactly that alias (in ~/.gitconfig for example):

[alias]
    rdiff = "!sh -c 'git fetch \"$0\" && git diff \"$0\"/\"$1\"'"

which tells shell to run the above command with the given parameters.


Some other notes:

  • Instead of git diff master, you can simply write git diff which takes the diff with the current branch you are on which is not necessarily master.
  • Instead of git diff master foo/master, you can simply write (if there are no local changes) git diff foo/master which does the same. It's easier to type since you don't repeat master twice.
  • You don't need to change your remotes every time. You can have multiple remotes in the same repository. Therefore, you can do (note that you missed add):

    git remote add foo git@github.com:user/foo.git
    

    and keep it there in your repository forever. Now you can still interact with origin, which is the remote automatically created when you cloned your repository. At the same time, you can also interact with the other remote you created, named foo. So in the same repository, you could do:

    # get updates from origin
    git fetch origin
    git merge origin/master
    
    # check them against foo
    git rdiff foo master
    
于 2013-11-06T13:49:50.483 に答える
0

@Shahbazに感謝します。

rdiffは、ローカル リポジトリとリモート サーバーの違いを取得するために使用されます。エイリアスは次のとおりです。

rdiff = "!bash -c 'git fetch && git diff master remotes/origin/master'"

次のようになります
rdiff

また、「rlog」と「rlogs」も作成して、リモート サーバーからログを取得します。

plog = log --max-count=3 --color --graph\n --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C( blue)<%an>%Creset'\n --abbrev-commit --date=relative
plogs = log --color --graph\n --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(blue)<%an>%Cr eset'\n --abbrev-commit --date=relative
rlog = "!bash -c 'git fetch && git plog remotes/origin/master'"
rlogs = "!bash -c 'git fetch && git plogs remotes/origin/master'"

次のように表示されます。
ログ

于 2013-11-07T11:57:27.170 に答える