1

So, I have some committed files in branch A, but I feel like they really don't belong there. I want to move them, as they are, to another branch B - but I don't want to bring the entire branch A history to B; I just want the files.

Then, I'm looking for a way to stash those files, and then pop this stash on a brand new branch B. I've done this in the past in a pretty trashy way - that is, I literally modified every file adding a new line at their beginning, so they could be stashed. Obviously, this solution is nowhere near smart. Is there any way to stash them?

(other solutions to this task are most welcome as well, by the way)

EDIT: I realize this question is badly written. I should have asked "how to move files between branches", because that is my real goal. Sorry for falling to the XY problem. Anyway, for that question, there is already a great answer - check it out. I'm keeping the question in order to help others who may phrase their problems the same way I did.

Lucas Lima
  • 832
  • 11
  • 23
  • 1
    Stash isn't the right tool for this job. Just move the files and then merge/rebase. – Tim Biegeleisen Feb 21 '20 at 01:40
  • I'm kinda realizing now that I should name this question "How to move files from one branch to another" - but then there are already sufficient answers for that question (which already solved my problem)... I kinda messed up this one; don't know how to proceed. – Lucas Lima Feb 21 '20 at 01:50
  • You can edit your own question, request to close it as a duplicate, or whatever you like :-) – torek Feb 21 '20 at 02:23
  • I edited it, but I will ask for closing as well. Thank you. – Lucas Lima Feb 21 '20 at 02:24

1 Answers1

1
  1. You could simply checkout a new branch
  2. then commit your change into your new branch
  3. then checkout the original branch you were on
  4. pull the changes from origin
  5. then simply cherry-pick the commit from #2 above
Priyesh Patel
  • 166
  • 2
  • 6
  • Thank you. I've ended up following the approach I mentioned in the question, after the edit (which I found out to be simpler). – Lucas Lima Feb 21 '20 at 16:05