38
Awlex
5y

My coworker enlightened me with git stash. Just :woah:

Comments
  • 14
    Also, git stash -u will also stash new files (un-tracked) in the workspace that haven't been added to the repo yet.
  • 4
    fuck, I know that too!
    ...
    I know I'll show off with something else...
    whenever you fuck up things in git, like in a rebase, and you lose reference to a specific commit, run git reflog, and you will see a history of all commits globally...
  • 1
    @duckWit Also nice to know.
    I'll open the manuals for this command, or else I'll miss some other nice features. Thanks!
  • 11
    @erandria I always think "re-flog" when I read or type that command.

    "I flogged thee once, and by the devil I will flog thee again!"
  • 3
    @Root lol... there was this old satire interview with linus (as in fake) where linus said that rebase was a joke, a reference to freebase.

    I actually didn't know it was satire until moments ago while googling that, and I wasn't the only one apparently:
    https://stackoverflow.com/questions...
  • 3
    @erandria 😅
    I should totally read through git's source someday. I'd learn quite a bit.
  • 4
    My most common use of stash is when I make a load of changes before realising I'm on the wrong branch. A daily occurrence for me.

    I didn't know about the -u flag though, that's today's lesson learnt!
  • 3
    While on the topic of git, has anyone ever tried using bisect?
  • 3
    If you're on a feature branch (and you should be...), you do not need to stash, just commit the changes (with reasonable commits, may be more than one), You can clean up the branch afterwards.

    If you were on master (which you shouldn't), you can just checkout a new branch and commit the changes to that branch.

    In both cases you're fine to change to whatever must be done immediately.

    Just always keep in mind that branches are cheap in git. Use many of 'em.
  • 2
    @beegC0de Sure. Never used bisect? Never had a bug and needed to know when it was introduced?

    Try it, it may seem to be a simple feature as you could checkout the same way manually, but then you have to keep track of the status. It relieves you're brain and gives you more room to concentrate on important aspects of debugging.
  • 1
    One word. GitKraken.
    Packages most of the things git can do so nicely.
  • 1
    @ddephor I've fallen in love being able to open a console with Ctrl P, typing history, then the file name, and getting all commits where the file was changed and what has changed bit by bit
  • 1
    @beggarboy That's an odd way to limit yourself. git log and its gazillions of options are way more powerful than the shell history and git blame is also helpful.

    And if you don't know where the bug comes from, you can't search for a file.

    Seems like you have been using git mainly for yourself. In this case you won't need the complex parts of git, because you will almost never conflict with yourself or make changes you're not aware of. But if you're working on a big codebase with more people it's not as easy as grepping the history.
  • 1
    @ddephor I don't think you're quite following. I am referring to GitKrakens history, not any git shell command.
  • 2
    @duckWit hmm your name sounds familiar
  • 3
    @beggarboy Ah, ok. I only use git on the command line. Mainly because I don't like the odd and confusing command naming of most git GUI clients (and I really don't understand why pure git clients need to invent their own naming of git commands) and because I haven't found one that supports all everday git procedures. They all fail when the going gets tough.
  • 2
    @fuckwit Indeed. I'm the punny version, I suppose. :D
  • 2
    @ddephor git bisect is so underrated. I haven't seen people using it in their projects.
  • 2
    @Root omg I always thought it was re-flog 😂😂
  • 1
    Oh, I found about this last week and it blew my mind!
  • 2
    You can even have multiple stashes and name them:
    git stash push -m “I did the stuff!”
  • 2
    git bisect

    I've never used it, but this thread has inspired me to try it out 👍
  • 3
    @duckWit Ohhhhh man, pro tips. I had no idea about that -u. Thank ye sir!
  • 1
    @swisspencilcase Yes, right. In fact it's quite a simple feature, but it can show you where to start the search for a bug.

    And I think many developer assume that it's complex and hard to use, but it's not.
  • 0
    @beggarboy GitKraken shits itself the very moment you try to change, commit and push a submodule (which is really the only way to easily develop dependencies together with their dependents, and it works fine in the CLI.
Add Comment