4 ms·
Handy Git commands that save my day
- kalmar 16y agoSigh. I was hoping for a list of commands that would be useful to someone how'd consider themselves an intermediate user. Instead -- as I should have expected from the title's style -- I got a survey of mostly basic commands, none of which have ever come close, I would wager, to saving anyone's day. No mention of git-stash. It can save a lot of time, though perhaps not enough to make up someone's day. Nor of git-reflog, which was the command that I'd say came closest for me: early on when the function of the commands was alien to me, discovering git-reflog massively increased my confidence tinkering with git commands. Not even a mention of the -i option to rebase. In short: if I could down-vote, I would. This comment is in lieu of that.
- masklinn 16y agoThough, really, stash and rebase -i don't save lives (or even days, especially stash since git has the index). Reflog on the other hand, yes.
- bshep 16y agogit-bisect sounds really useful! Now all we need is a script that we can run like this: git-bisect-auto good-commit bad-commit test-command That returns the id of the first commit that breaks the tests
- gruseom 16y agogit bisect run
- alexkay 16y agoIt's built in [1]: $ git bisect start <bad> <good> $ git bisect run <script> [1] http://www.kernel.org/pub/software/scm/git/docs/git-bisect.html http://www.kernel.org/pub/software/scm/git/docs/git-bisect.h...
- bshep 16y agoAwesome! This will come in really handy for me!
- tzs 16y agoSimilar in Mercurial. And Bazaar. And Darcs. And Monotone.
- masklinn 16y agoNot bazaar as far as I know. Not builtin anyway, and doesn't seem to be in macport's bzr extensions set. In darcs, it's called `trackdown` and mandates usage of a test command, it cannot be used "interactively" (via $vcs bisect --good/$vcs bisect --bad the way git and mercurial can do it)
- user0 16y ago> Not builtin anyway Yes. Its a plugin[1] for bzr. [1] https://launchpad.net/bzr-bisect https://launchpad.net/bzr-bisect
- ajb 16y agoNot built in, on the other hand, is 'bbchop', which is like bisect, but for intermittent bugs: http://github.com/Ealdwulf/bbchop http://github.com/Ealdwulf/bbchop
- sumeeta 16y agoIn the beginning, you mention that you use bash as your terminal. You might want to correct that.
- dalore 16y agoFor his first case rather then merging his feature branch into master he should instead merge his master branch into his feature one. Do this regularly if you can (without interrupting your feature development) then when it comes time to merge your feature branch into master it should be conflict free as you worked your conflicts when you pull master into the feature branch.
- zacharypinter 16y agoSpeaking of git-blame, I find putting the following function in my .bashrc extremely useful: gblame() { find . -name $@ | xargs git blame }
- DCoder 16y agoSomething I came up with when deploying updates to hosts that don't support git, for example, a windows server we have RDC into: alias gdate=date\ +%Y.%m.%d-%H.%M.%S gitzip () { zip -ruv "$(gdate).zip" $(git diff $@ --name-only); } Produces a zip file of all files that changed since the commit you pass as the argument. Then I just transfer the resulting zip over, and unzip its contents to the root project folder. Haven't figured out how to deal with deleted files this way yet, fortunately that's not common. -- And a pre-commit hook for linting PHP source code when I'm not in an IDE. Yes, this came around because of a few commits made without testing. #!/bin/sh exitStatus=0 for i in $(git diff --name-only --staged HEAD); do [ "$VERBOSE" != "" ] && echo "Validating file $i" echo "$i"| grep -q '.php$' if [ $? -eq 0 ]; then [ "$VERBOSE" != "" ] && echo "... seems to be PHP, running php lint" php -n -l "$i"| grep -q 'Errors parsing' valid=$? if [ $valid -eq 0 ]; then echo "File $i is invalid." exitStatus=1 fi fi done exit $exitStatus