简体   繁体   中英

Shuffling committed changes between git branches and then deleting them on the source

Please note: I understand my question is very similar to this one -- however there IS a slight difference! Please ready this question in its entirety!


New to git, I made a bunch of changes on my project's develop branch, whereas it seems I should have cut a feature branch off of develop first and made my changes there. I have already added ( git add . ) and committed ( git commit -m "blah" ) my changes but I have not pushed them yet.

I'm hoping there is a way to:

  1. Create a new branch off of my local develop and move my changes over to it
  2. Reset my local develop so that its as if I never made changes to develop in the first place

From the question I referenced above, it seems that the correct solution is something like this:

git checkout -b newbranch
git merge develop
git checkout develop
git reset --hard HEAD~X # Go back X commits
git checkout newbranch

Here's how my question is different than the one I mentioned:

The problem is: this is a very active project and MANY (30+) commits by MANY other developers have transpired since I started making my local changes.

So I'm note sure what the real value of HEAD~X needs to be!

Ideally, I'd like to just say: " Hey git , whatever is the latest on the remote develop , yeah, set my local develop to that commit and completely blow out/erase any of my committed changes to it. "

Is this possible to do?

You are on the right track. Just create a new branch from the current point in your local develop branch, then reset off the commits you added:

# from develop
git branch newbranch
git reset --hard HEAD~1   # assuming you only made one commit

Replace the 1 in HEAD~1 with however many commits you did actually make to develop before realizing that your work belonged in its own branch.

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