且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用git,如何将一些未提交的更改从一个分支移动到另一个文件夹中的另一个分支?

更新时间:2023-01-05 08:06:11

在包含更改的目录中,执行以下操作:

$ git diff > patch

cd到另一个目录,然后执行:

git apply /path/to/patch

I have two different branches of the same software that I work on every day. However, every time I checkout the other branch, my build process can take up to an hour. To solve this, I have just checked out the project once for each branch in two separate folders.

I did some work in one branch, and realized before committing it that I was in the wrong folder, and thus the wrong branch. How can I move the work I did on this branch, to the other branch, preferably without creating a commit (if that is even possible)?

In the directory with the changes, do:

$ git diff > patch

cd to the other directory, and do:

git apply /path/to/patch