简体   繁体   中英

Rebase current branch to a previous commit version in GIT

I am in my current branch say "feature/Sprint2" With the following commits:

  1. c1004
  2. c1003
  3. c1002
  4. c1001
  5. c1000

Now i want to update my current branch to c1002 and update the current branch..after which the commits will look like:

  1. c1002
  2. c1001
  3. c1000

Whats the commands?

Since you didn't tell me your situation I will consider a couple cases and give you advice on what to do in those cases.

Case 1: You want to keep the code but drop the commits

git rebase -i <c1001 commit hash> 
<change the pick to fixup for c1003 and c1004>
<save your text editor> 
git push -f origin feature/Sprint2

Case 2: You don't want to keep the commits or the code

git reset --hard <c1002 commit hash>
git push -f origin feature/Sprint2

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