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 558387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:07:35+00:00 2026-05-13T12:07:35+00:00

Coming from Sourcesafe, I have primarely been using git as a major undo feature.

  • 0

Coming from Sourcesafe, I have primarely been using git as a major undo feature. I tend to
work in the master branch, code happily away for some time, commit here and there and move on.

While I’m coding my brains out, I sometimes wish to drop what I’m doing right
now and start working on another feature. I know I can start another branch right now but let’s assume I’d like to keep working on master. I should have branched when
I started working on the previous feature but that would have required me to plan ahead (at which I’m terrible btw).

I am pretty confident that what I need is possible with git, but I can’t get my head
around it. As a picture tells more than a thousand words, schematicly this is what I would like to do:

0--1 master

0--1--2 master

0--1--2--3 master

0--1--2--3 aBranch    
    \-4    master

0--1--2--3 aBranch    
    \-4--5 master

Edit: I should clear up that every number is a commit.

  • 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-05-13T12:07:35+00:00Added an answer on May 13, 2026 at 12:07 pm

    Yes, this is possible, and not hard. The short version: git branch aBranch to create the new branch, git stash to save any uncommitted changes, and git reset --hard 1 to reset master to the commit you would like, and optionally git stash pop to apply those uncommitted changes to your current working copy, if they were intended for the new master branch.

    Here’s a full explanation, with diagrams so you can follow along. In the following, I will notate the current branch (HEAD) with a *.

    0--1 *master
    
    0--1--2 *master
    
    0--1--2--3 *master
    

    Create new branch aBranch pointing at the current commit:

    $ git branch aBranch
    
    0--1--2--3 *master aBranch
    

    If you have any changes in the working copy that haven’t yet been committed, save them with a stash (this is important, as git reset --hard will wipe away any uncommitted changes you have):

    $ git stash
    
    0--1--2--3    *master aBranch
             \- 4 stash
    

    Now reset master back to the revision you want it at. I’m using 1 below as a placeholder; you may want to use the SHA-1, or something like origin/master if you want to reset it to the revision that the upstream master branch was at before you made your commits:

    $ git reset --hard 1
    
    0--1--2--3    aBranch
       \     \- 4 stash
        \-        *master
    

    If you had uncommitted changes in your working copy that you stashed away, and you want to apply them to master, you can use git stash apply or git stash pop (apply will leave the stash recorded as a commit; pop will clean up the stash).

    $ git stash pop 
    
    0--1--2--3 aBranch
       \-      *master (with stashed changes now back in your working copy)
    

    Now you’re on master, and reset to commit 1, exactly as you wanted to be. New commits will go to the master branch.

    0--1--2--3 aBranch    
        \-4    *master
    
    0--1--2--3 aBranch    
        \-4--5 *master
    

    Note that if your working copy is clean (nothing reported by git status), you don’t need the git stash command. If you wanted to apply your changes to aBranch instead of master, you would just use git stash pop the next time you switched back to aBranch and started working on it again.

    One important point to keep in mind is that you should only edit branch history like this in your own private repositories, not public ones that other people could pull from. If you push this to a public repository that people are pulling from, then they’ll have to rebase all of their changes, and it’s best not to make them do that unless absolutely necessary.

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

Sidebar

Ask A Question

Stats

  • Questions 402k
  • Answers 402k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're relying on things such as callback URLs, then… May 15, 2026 at 4:56 am
  • Editorial Team
    Editorial Team added an answer Save yourself the pain and just use a value convertor… May 15, 2026 at 4:56 am
  • Editorial Team
    Editorial Team added an answer There is a solution. Consider the following: public sealed class… May 15, 2026 at 4:56 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.