简体   繁体   中英

Using git, how do you move some uncommitted changes from one branch to another branch in a different folder?

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

Well, you can also not build the other branch..

  1. Make the change, don't commit
  2. Switch to the other branch
  3. Commit (don't build)
  4. Come back

Naturally, this only works if you can allow yourself to commit without building (reasonable in some scenarios).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM