Live data from Hacker News

Some bad Git situations and how I got myself out of them

ohshitgit.com

21–30 of 352 posts

Re: Some bad Git situations and how I got myself out of them

#21

I don't know if this post was intended as humour or a way to vent out some frustration but in my experience, this path of treating git as "spell X solves problem Y" will always break down. Version control systems are an important part of the programmers toolkit and it's worth investing a little time to get the fundamentals right. Sure git is not the friendliest of beasts but what it lacks in interface, it more than m…

Git has enough bells and whistles that a cheat sheet is fine, in my opinion. It's only a problem if you don't understand the commands (the same problem as blind copy-pasting code from the web)

Re: Some bad Git situations and how I got myself out of them

#22

> Oh shit, I accidentally committed to the wrong branch! Other ways to do it (that don't require to retype the commit message): - rebase onto the correct branch: git branch foo git reset --hard HEAD~ git rebase --onto name-of-the-correct-branch HEAD foo git checkout name-of-the-correct-branch git merge foo git branch -D foo - cherry-pick git reset --hard HEAD~ git checkout name-of-the-correct-branch git cherry-pick n…

for the first one, you don't need rebase afaik:

    git branch name-of-the-correct-branch
   
    git reset --hard HEAD~

    git checkout name-of-the-correct-branch

Re: Some bad Git situations and how I got myself out of them

#23

I don't know if this post was intended as humour or a way to vent out some frustration but in my experience, this path of treating git as "spell X solves problem Y" will always break down. Version control systems are an important part of the programmers toolkit and it's worth investing a little time to get the fundamentals right. Sure git is not the friendliest of beasts but what it lacks in interface, it more than m…

it was really hard for me to understand vim until a website explained it as being a set of grammars you can learn.

i agree, if you really want to be more productive (and without having to go find some git expert on your team) knowing how each operation works and why its doing what its doing is really beneficial.

despite that, its sometimes frustrating due to inconsistencies in the git "grammar" that i sometimes don't understand, like why if you want to apply only one file from git stash you have to use `git checkout` rather than `git stash apply [] -- `. it makes "sense" but is unintuitive when i'm thinking about using stashed commits.

Re: Some bad Git situations and how I got myself out of them

#24
post #23

I don't know if this post was intended as humour or a way to vent out some frustration but in my experience, this path of treating git as "spell X solves problem Y" will always break down. Version control systems are an important part of the programmers toolkit and it's worth investing a little time to get the fundamentals right. Sure git is not the friendliest of beasts but what it lacks in interface, it more than m…

it was really hard for me to understand vim until a website explained it as being a set of grammars you can learn. i agree, if you really want to be more productive (and without having to go find some git expert on your team) knowing how each operation works and why its doing what its doing is really beneficial. despite that, its sometimes frustrating due to inconsistencies in the git "grammar" that i sometimes don't…

The absolutely easiest way to learn vim is to just schedule a reminder every ... month? week? to run "vimtutor". Then do that for a few minutes until you get frustrated or want to do something else. It's shocking how fast you'll learn.

Re: Some bad Git situations and how I got myself out of them

#25
Not quite in the spirit of this article, but "I just want this /one/ file without the rest of the changes from branch foo" is something I use all the time

    git checkout otherbranch
    git checkout firstbranch -- fileIwant maybe1more
    git commit -m "brought over files"

Re: Some bad Git situations and how I got myself out of them

#27

I managed to "rm -rf .git" at one point. Took me about a minute to realize and -surprisingly after -ing i lost nothing (as far as i was aware). Git is freaking hard to break. Also always remember git-reflog, it safes lives.

What do you mean by -ing?

Re: Some bad Git situations and how I got myself out of them

#29
post #27

I managed to "rm -rf .git" at one point. Took me about a minute to realize and -surprisingly after -ing i lost nothing (as far as i was aware). Git is freaking hard to break. Also always remember git-reflog, it safes lives.

What do you mean by -ing?

Control C to cancel

Re: Some bad Git situations and how I got myself out of them

#30
post #23

Earlier quoted context omitted.

it was really hard for me to understand vim until a website explained it as being a set of grammars you can learn. i agree, if you really want to be more productive (and without having to go find some git expert on your team) knowing how each operation works and why its doing what its doing is really beneficial. despite that, its sometimes frustrating due to inconsistencies in the git "grammar" that i sometimes don't…

The absolutely easiest way to learn vim is to just schedule a reminder every ... month? week? to run "vimtutor". Then do that for a few minutes until you get frustrated or want to do something else. It's shocking how fast you'll learn.

[deleted]
Post reply on HN