Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8746745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:14:35+00:00 2026-06-13T12:14:35+00:00

my git log is like this: commit 7cfdafdad623d2529f9c2069549619d117f4f43ec commit afdafdafd0165af0651c1c4670bc2cd53738c2433 commit 1235cebdd758c1314ca0002a2c11f9693f43deafb … How

  • 0

my git log is like this:

commit 7cfdafdad623d2529f9c2069549619d117f4f43ec
commit afdafdafd0165af0651c1c4670bc2cd53738c2433
commit 1235cebdd758c1314ca0002a2c11f9693f43deafb
...

How can I move the most recent 2 commits to a new branch? (Note: most recent are at the top)

I am thinking

git branch newbranch
git reset --soft HEAD~1
git checkout newbranch
git commit -a 
git checkout master
git reset --soft HEAD~1
git checkout newbranch
git commit -a

Is there a better way? I think my way will lost the git comments. I kind of remove the commit and re-check in.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:14:35+00:00Added an answer on June 13, 2026 at 12:14 pm

    You can simply issue the following two commands:

    git branch new_branch_name
    git reset --hard HEAD~2
    

    Explanation:

    1. Create a branch called new_branch_name in the current (latest) commit, but don’t checkout that branch.
    2. You’re still on the old_branch. Next step is to point it to 1235ce. This is done using reset --hard.

    Now old_branch is pointing to 1235ce, and new_branch_name is at 7cfdaf.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my git log, I have 2 commits. How can I generate the difference
Given a history like this: create new branch foo at commit a111 add 3
I'm very new to git, and was wondering if something like this is possible?
When looking at the latest git commits, I know you can do git log
git diff --stat and git log --stat show output like: $ git diff -C
I have squashed 2 commits (A and B) into one new commit (C). The
I read a similar question about this that suggested using git log --graph --all
Desired: I'd like to be have my git commits reference some higher order/level task
Currently I'm using git log --graph --all to visualize my repo's history I'd like
Let me preface this by saying that I am relatively new to git so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.