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

Alex Flores
Alex Flores
7,864 Points

Starting from a previous commit (Git)

Hello all!

I have a couple questions regarding using Git with WordPress.

  1. Is it possible to go back to a previous commit and then start again from there. Basically re-writing all commits that took place after it? I figured I could go back to a previous commit and then branch from there and then merge my branch back in with the Master. Is there a better way?

  2. While using WordPress, say I want to branch off and try something new that I just want to test. So I create a new branch and make the changes I wanted to test. How do I actually access the backend or even the front end of my localhost site? When I checkout to a previous commit and then go to the website, it says, "The theme directory "THEME NAME" does not exist.".

Any help would be much appreciated. Thanks guys/gals!

3 Answers

For your first query you're looking for git reset.

As for the second, if you've both created a new branch and switched to it then it should work fine:

git branch branchname
git checkout branchname

Or in one step:

git checkout -b branchname

Of course if some of your code is referencing some files that you've deleted in the branch, then it won't work, since switching branches will delete any files that don't exist in the branch (unless they are set to being ignored in your .gitignore file).

Sue Dough
Sue Dough
35,800 Points

One thing I want to mention:

You can checkout any commit any time:

run

git log

Press q to quit once you find a commit ID you want to select

Then simply run

git checkout 58bf307669d7799dbd4107398d72abc36615e772

This will allow you to go back in history on any commit.

Git reset can also be very helpful but sometimes you don't want to reset and simply want to see something from a bit ago.

Alex Flores
Alex Flores
7,864 Points

Thanks Iain, much appreciated.