git 将存储导出到另一台计算机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3973034/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:19:20  来源:igfitidea点击:

Export a stash to another computer

git

提问by Marcelo A

I need a way to export a stashed change to another computer.

我需要一种方法将隐藏的更改导出到另一台计算机。

On Computer1 I did

在 Computer1 上我做了

$ git stash save feature

I'm trying to get the stash patch to a file and then import it to another computer

我正在尝试将 stash 补丁安装到文件中,然后将其导入另一台计算机

$ git stash show -p > patch

This command gives me a file that I can move to another computer where this repo is cloned, but the question is how to import it as a stash again.

此命令为我提供了一个文件,我可以将其移动到另一台克隆此 repo 的计算机上,但问题是如何再次将其导入为 stash。

Thanks

谢谢

采纳答案by poke

You can apply a patch file (without committing the changes yet) by simply running

您可以通过简单地运行来应用补丁文件(无需提交更改)

git apply patchfile

Then you can simply create a new stash from the current working directory:

然后你可以简单地从当前工作目录创建一个新的存储:

git stash

回答by Chris Maes

alternatively you can create a branch from your stash (on computer 1), using

或者,您可以从您的藏匿处(在计算机 1 上)创建一个分支,使用

git stash branch stashed_changes_branch

commit your changes:

提交您的更改:

git commit -a

then add it as a remote on computer 2:

然后将其添加为计算机 2 上的遥控器:

git remote add pc1 user@computer1:/path/to/repo

now you can retrieve the remote information using

现在您可以使用检索远程信息

git fetch pc1

now you can import the commit in the way you want; using git cherry-pick, git rebaseor whatever you like... If you want it to look like you just did git stash apply; you can use git cherry-pick --no-commit.

现在你可以按照你想要的方式导入提交;使用git cherry-pickgit rebase或任何你喜欢的......如果你想让它看起来像你刚刚做了git stash apply; 您可以使用git cherry-pick --no-commit。



If you have no direct connection between computer1 and computer2; you can use a remote (like github or something similar):

如果您的计算机 1 和计算机 2 之间没有直接连接;您可以使用遥控器(如 github 或类似的东西):

git push origin stashed_changes_branch

and on computer2:

并在计算机 2 上:

git fetch

回答by shafeeq

Alternatively you can export the entire local stashes to another compter as follows

或者,您可以将整个本地存储导出到另一台计算机,如下所示

  • git pullon both your old and new git directory to ensure that both having latest changes.
  • copy the .git folder from old git directory to new repository
  • git pull在旧的和新的 git 目录上,以确保两者都有最新的更改。
  • 将 .git 文件夹从旧的 git 目录复制到新的存储库

回答by KEMBL

How to do export Stash in SourceTree:

如何在 SourceTree 中导出 Stash:

  1. Make a new branch "StashTransfer" from a branch where you are going to use your Stash
  2. Apply your stash to it and make a commit

  3. Click on your commit and make a patch from it, take the patch file with you.

  4. Go to a different repository, select the same parent branch which you just used in 1)

  5. Actions / Apply Patch, select Mode: Modify working copy files, push Apply Patch now you have uncommitted modifications from the patch in your current working environment

  6. Make a new Stash for the current repo

  1. 从您要使用 Stash 的分支创建一个新分支“StashTransfer”
  2. 将您的藏匿处应用到它并进行提交

  3. 单击您的提交并从中制作补丁,随身携带补丁文件。

  4. 转到不同的存储库,选择您刚刚在 1) 中使用的同一父分支

  5. 操作/应用补丁,选择模式:修改工作副本文件,推​​送应用补丁,现在您在当前工作环境中对补丁进行了未提交的修改

  6. 为当前的 repo 创建一个新的 Stash

回答by steampowered

Another option is to rsyncthe .gitfolder from one computer to another computer. rsyncprocesses only file changes (faster than a copy).

另一种选择是rsync.git文件夹从一台计算机转移到另一台计算机。 rsync仅处理文件更改(比副本快)。

One downside to this approach is the configs would also be overwritten, which may not be desired if you run different .git configs between the two machines. But you could overcome this by excluding files with the --excludeoption in rsync.

这种方法的一个缺点是配置也会被覆盖,如果您在两台机器之间运行不同的 .git 配置,这可能是不希望的。但是你可以通过与排除文件克服这一点--exclude的选项rsync

Overall I think a native Git solution is cleaner, but this rsynchack could be nice for someone in a hurry who might be more familiar with rsync than git.

总的来说,我认为本机 Git 解决方案更简洁,但是rsync对于赶时间的人来说,这个hack 可能会很好,因为他们可能比 git 更熟悉 rsync。

回答by pizon

The startup command from the original post:

原帖中的启动命令:

git stash show -p stash@{x} > patch_file

didn't work for me (for some reason it created unusable patch files). Instead I had to:

对我不起作用(由于某种原因它创建了无法使用的补丁文件)。相反,我不得不:

git stash apply stash@{x}
git commit

for each stash I wanted to transfer. Then, I placed the 'parent' repo within file:/// reach of the 'child' repo, and did the following, for each stash commit:

对于我想转移的每个藏匿处。然后,我将“父”存储库放在“子”存储库的 file:/// 范围内,并为每个存储提交执行以下操作:

git fetch file:///path_to_parent_git && git cherry-pick commit_sha
git reset --soft HEAD^
git stash save my_new_stash_on_child

This is more complex but did the trick for me.

这更复杂,但对我有用。

回答by Sam

You can create stash as patch file from one machine,then can share that patch file to another machines.

您可以从一台机器创建 stash 作为补丁文件,然后可以将该补丁文件共享到另一台机器。

Creating the stash as a patch

将存储创建为补丁

$ git stash show "stash@{0}" -p > changes.patch

The “stash@{0}” is the ref of the stash.It will create patch file with latest stash. If you want different one use command $ git stash listto see your list of stashes and select which one you want to patch.

“stash@{0}”是 stash 的 ref。它将使用最新的 stash 创建补丁文件。如果您想要不同的使用命令$ git stash list来查看您的存储列表并选择您要修补的一个。

Applying the patch

应用补丁

Now transfer that stash to another machine and paste it into the root folder of your project. Then run this command

现在将该存储转移到另一台机器并将其粘贴到项目的根文件夹中。然后运行这个命令

$ git apply changes.patch

If there is mistake and you want to reverse the change

如果有错误并且您想撤销更改

$ git apply changes.patch --reverse

回答by Siriquelle

If you want to move your changes from one machine to another you could always commit your changes on your machine and then do a soft reset on their machine.

如果您想将您的更改从一台机器移动到另一台机器,您可以始终在您的机器上提交您的更改,然后在他们的机器上进行软重置。

Office

办公室

git commit -m "-stash-"

git commit -m "-stash-"

Kitchen

厨房

git reset --soft HEAD~1

git reset --soft HEAD~1