Help! I've messed up my project's repository!

Hey all, so I’ve started using GIT and have my code in a repository. I’ve been saving changes and committing them and so far so good. Even had a new branch created. But tonight I’ve messed something up.

I had made some changes so I wanted to go back to a previous commit to experiment with something So I committed my changes and then attempted to pull down a previous commit. That didn’t work. So then I checked out that commit and suddenly got this message about being in a detached head state. Now the origin of the branch I was working on has been changed to my last commit and I can’t get it undone. I keep getting file conflict errors and that if the change was undone it would overwrite things. Well, that’s what I want to happen!

I’m using Fork and Fork has absolutely ZERO documentation. So I have no clue what I am doing.

I thought this was supposed to be simple…

Like a lot of things, it gets simpler with experience.

Don’t do anything more. If you’d like, I can do a Zoom session with you in about an hour.

7 Likes

I am available now or anytime for the next 45 minutes.

I messaged a Zoom link to you.

@Jon_Ogden, I remembered the other thing I meant to tell you…

Say you’re in the develop branch and you make some changes, then realize you really should start another branch for those. Without staging or committing your changes, start a new branch, then stage and commit. Those changes will be part of the new branch instead of the develop branch.

Got it. Makes sense. Thank you.

This is what this forum is all about. Good job, Kem, and all the rest of you who go out of your way to help each other. I am privileged to know you.

7 Likes

Yeah, I am extremely appreciative of the time Kem took to help me out. The Jedi master taught the padwan quite a few things about Git. It is very appreciated!

1 Like

Here’s another scenario I was thinking of and let me make sure I have this correct.

Let’s say I have released my code and have gone off on numerous branches for various development work, etc. None of it shippable. A customer contacts me and let’s me know that they found a bug. I see the bug and can easily fix it.

The Non-Version Control Way: I have to go to an old back-up of my project and make the bug fix there as well as in my current project. Or I have to comments out or choose not to compile my new changes, etc. Then I release the fix and go back to working on my new stuff. It’s definitely not efficient and you can propagate errors pretty easily.

The Version Control Way: I checkout my Master branch. I make a new branch where I then implement the bug fix and test it out. Since I’m using GitFlow I assume that this would be a hot-fix branch. Once I am satisfied with these fixes, I then merge this branch into the master and release the update. I then merge the master into my development branch as I want these new fixes in the new code I am working on.

Am I understanding this correctly?

Thanks…

Yes. But if you go through GitFlow to start and finish the hot fix, it will do all that merging for you.

After that, it’s on you to manually merge develop back into the other branches you’ve created so they can have that hot fix too.

Wouldn’t I want to merge the hot fix into the development branch?

Yes, exactly as you described in your post. GitFlow has the option to both start a hot fix (or feature or release) branch and finish it. If you use that, it will merge your changes back into both master and develop for you.

Ah. Got it. So it’s done automatically but other branches that are outside of GitFlow would need to have a manual merge.

1 Like

Again, I like to suggest to consider using SmartGit - it allowed me to use git without ever reading the docs - that’s how well it guides me (I have to browse the menus sometimes, but hardly ever needs the git docs to understand how to get out of something like you had).

It’s not having “guide” per se, but, for instance, if you have a merge conflict, it highlights the affected files and offers buttons that explain what options you have (e.g. either fix all conflicts or cancel the whole thing with one simple click, and then try again). For your case of a “detached head state” it offers similar options, I believe.

1 Like