Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Basics Getting Started With Git Looking Back on What We've Done

David Forero
David Forero
5,492 Points

Continuing with an older commit because of mistake

How do I go back with the checkout option and start working from an older commit to replace newer error filled code? I know how to check the logs and how to "check out" the code but how do I continue working with the old commit?

Thanks

1 Answer

Assuming you currently have no uncommitted changes you can reset your current branch back to a specific commit with git reset --hard <hash>. You may have to use --force when pushing to a remote with this though.

David Forero
David Forero
5,492 Points

If I have committed both in the master and in the current branch changes what can I do?

What are you looking to revert? A change in master, in the branch, or both? If the buggy commit exists in both master and the branch you may end up creating an orphan branch after reverting it.

David Forero
David Forero
5,492 Points

Since my last commit i have made various errors in my code and would like to jump back to that previous commit to avoid having to debug the newly erroneous code.

Thanks