1

Well I've been working for a project. today I was experimenting with windows specific wchar and I needed to do change a lot of code since morning and I ended up with an ugly mess. That I can clear out latter but right now I need to do some mainstream works on last working commit. But I don't want to loose this work. So how can I keep this work in some branch for future and revert my workspace back to last commit ?

Neel Basu
  • 12,638
  • 12
  • 82
  • 146

4 Answers4

2

You can create a new branch and commit your changes to it:

git checkout -b topic/ugly-mess
git commit -a -m 'Checkpointing mess.'

Then go back to your mainstream branch which has the last working commit:

git checkout master

If you want your to publish your "local mess" upstream, push the branch:

git push origin topic/ugly-mess
mavam
  • 12,242
  • 10
  • 53
  • 87
  • don't I need to push after commit and before checkout master ? – Neel Basu Aug 15 '12 at 18:35
  • You only need to push if you want your "local mess" to be available upstream. (I modified the answer accordingly.) – mavam Aug 15 '12 at 18:41
  • Yes I want that mess to be available upstream for future such that I can play with it latter. do I need to push it after checking out master ? and do I need to explicitly specify the name of branch ? – Neel Basu Aug 15 '12 at 18:44
  • Regardless of the push, the branch will be available in the future. You can always check it out via `git checkout topic/ugly-mess`. Pushing it upstream *(i)* makes a it available to other users, and *(ii)* backs it up in case your local disk fails. And yes, you need to specify the branch if you are currently in master and want to push another branch. You could [setup tracking](http://stackoverflow.com/q/1519006/1170277), though, to avoid specifying the branch name when pushing. – mavam Aug 15 '12 at 18:49
  • But If I don't push It will be available **locally** only ? – Neel Basu Aug 15 '12 at 18:51
1

Simply create a new branch

git branch -b wchar_migration

and commit your changes into it

git commit -am "wchar ..."

then go back to your work

git checkout master

If later you want to include the modification you made on master, simply rebase on it.

git co wchar_migration
git rebase master
log0
  • 10,489
  • 4
  • 28
  • 62
0

You probably don't even need a branch. If you use git stash, git stashes (stores) the current 'dirty' workspace and returns you to a clean workspace. You can apply the stashed changes later if you want.

Wander Nauta
  • 18,832
  • 1
  • 45
  • 62
  • Yes, you can. Stashes are local, though, and are supposed to be short-lived, so I don't see why you would want to. Take a look at the git-stash manual page for all the options. – Wander Nauta Aug 15 '12 at 17:36
0

So long as you haven't committed any of this work, you can always git stash your experiment.

But you've described this as experimental so another option, and probably the better one, is to keep this work in it's own branch, e.g. git checkout -b wcharExperiment, commit the work into this new branch, then checkout your main branch.

pb2q
  • 58,613
  • 19
  • 146
  • 147