Eric at Lucii.org on 25 Oct 2012 10:35:24 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] git-fu |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Thanks. yes, I need to start doing all my work in branches as you suggest. I've read that before but have not yet developed that habit. Eric On 10/25/2012 12:53 PM, Frank Szczerba wrote: > Eric, > > You can also directly create a branch at the desired point. > > $ git branch branch_name head~1 > > If you have made several commits since the desired branch point, you can use a sha1 to identify the desired commit: > > $ git log < find the sha1 of the commit you want to base the branch on > $ git branch branch_name commit_sha1 > > When you are ready to switch to working on the alternate approach, just check out the branch as normal. > > If you decide to move master to the new branch, the easiest way is to just reset master. This is fine if you haven't shared the changes yet: > > $ git branch -M master > > If you _have_ shared the changes, then you should avoid rewriting history: > > $ git checkout branch_name # if necessary $ git merge -s ours master # create a fully merged commit with our tree $ git checkout master # switch to master $ git merge --ff branch_name # fast-forward to the merged commit $ git branch -d branch_name # clean up the working branch > > As you said, there are many ways to do it. > > Since branches are so cheap and easy to work with in git, you should consider doing _all_ development work on topic branches, merging into master only when it's tested and working. If you only work on one thing at a time, the merge to master will likely be a fast-forward, but you'll always have easy access to a "last known good" version of the code. > > Frank > > On Oct 25, 2012, at 12:13 PM, Adam <adam@fromonesrc.com> wrote: > >> Commit your changes then >> >> git reset --hard head~1 >> >> That will set you one commit back. Then >> >> git checkout -b branch_name >> >> Will put you on a new branch >> >> On Oct 25, 2012, at 12:04 PM, "Eric at Lucii.org" <eric@lucii.org> wrote: >> > My limited git skills are proving to be insufficient today. > > Background: I made some code changes and committed them. I subsequently made more changes but now I'm thinking I /may/ have gone down the wrong path. > > I'd like to go back to the last commit, create a branch, and try another approach in that branch. How can I do that without losing the current changes in the event I want to come back to them? > > Presumably, if the new branch works then I'd merge it into master (and then I don't care about what happens to the current changes.) > > I suspect tmtowtdi. > > Eric >>> ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug >> ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug > > ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug > > - -- # Eric Lucas # # "Oh, I have slipped the surly bond of earth # And danced the skies on laughter-silvered wings... # -- John Gillespie Magee Jr -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://www.enigmail.net/ iEYEARECAAYFAlCJeFgACgkQ2sGpvXQrZ/5MiACg/J5SHmrdYHlhwqSwIUQePWIP wa4An3v1pxNVDs4KW/4YsaK0++6O/DZR =Ihbh -----END PGP SIGNATURE----- ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug