2

From this SO answer:

$ git --git-dir=../<some_other_repo>/.git \
format-patch -k -1 --stdout <commit SHA> | \
git am -3 -k

Is it possible to do same across servers? in other words, if git-dir is in different physical server, is it possible to use something like: --git-dir=otherServerName:/path/to/repo/.git ?

rodee
  • 2,759
  • 2
  • 32
  • 55

2 Answers2

1

One possible solution is to add the server as a remote:

$ git remote add <remote-name> <remote-uri>

Then fetch the changes:

$ git fetch <remote-name>

Now you have the commit directly on your machine without modifying any of your local branches. You can create a patch as in your question without the --get-dir option. If you want the commit with your current work, you can use git cherry-pick or any other appropriate git commands using the SHA hash directly.

Code-Apprentice
  • 76,639
  • 19
  • 130
  • 241
0

The git way would be to add the server temporarily as a remote repo and to cherry-pick the commit.

git remote add <name> <url>
git fetch <name>
git cherry-pick <commit SHA>
git remote remove <name>

If the repo, for example, is on GitHub or GitLab you could do something like this:

curl https://github.com/<user>/<repo>/commit/<commit SHA>.patch | \
git am -3 -k

Check the API documentation of your git server.

sergej
  • 15,727
  • 6
  • 44
  • 82