commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:
After cloning an empty repository on the client ("git clone" just after "git init", for instance), "git push" fails.
In order to be able to push to this repository for the first time, you need to run the above command. It will link your local "master" branch to the "master" branch in the origin server, and push the changes.
This is only necessary only for the first push; after that, you can use just the commands "git push" or "git pull" in order to do this operations.
Do a git commit using a random message.
Uses git grep for speed, relies on a valid she-bang, ignores leading whitespace when stripping comments and blank lines
Print a git log (in reverse order) giving a reference relative to HEAD.
HEAD (the current revision) can also be referred to as HEAD~0
The previous revision is HEAD~1 then HEAD~2 etc.
Add line numbers to the git output, starting at zero:
... | nl -v0 | ...
Insert the string 'HEAD~' before the number using sed:
... | sed 's/^ \+/&HEAD~/'
Thanks to bartonski for the idea :-)
Where $1 = author and $2 = mod name
You need to be running a daily build of Minetest (for example from the 'minetestdevs/daily-builds' PPA), or some bleeding edge mods will not work or crash the game.
Update a mod by entering its subdirectory under ~/.minetest/mods and doing
git pull && git submodule update --recursive --remote --init
Normally, searching git log comments is case sensitive. The -i luckily applies to the --grep switch.
A great command to assign to an alias, allowing you to git diff the last two commits in git.
Creating feature-branches off master, and trying to merge them in an integration branch (preview), sometimes causes conflicts because the feature-branch might hold changes from 'master' that aren't on preview yet. So this ensures only the commits added to the feature-branch are moved to integration (preview).
Note: This assumes you're currently on the feature-branch. Adjust 'master/preview' branch names to suit your environment.
For editing files added to the index:
vim `git diff --name-only --cached`
To edit all changed files:
vim `git diff --name-only HEAD`
To edit changed files matching glob:
vim `git diff --name-only -- '*.html'`
If the commands needs to support filenames with whitespace, it gets a bit hacky (see http://superuser.com/questions/336016/invoking-vi-through-find-xargs-breaks-my-terminal-why for the reason):
git diff --name-only -z | xargs -0 bash -c '</dev/tty vim "$@"' x
The last part can be put in a script named e.g. vimargs, and used with any command outputting NUL separated filenames:
git grep -lz foobar | vimargs
Delete all your branches except master (useful after archiving branches)
Description by segments delimited by pipe (|)
1. List all git branches
2. Exclude master
3. Trim output and remove display elements such as * next to current branch
4. Repeat branch name after a space (output on each line: branch_name branch_name)
5. Prepend each line with the git tag command
6. Execute the output with bash
This checks if the branch has been merged with master and then will delete the ones that have been. Keeps your local git repo nice and clean from all the branches.
List all dependencies manifests so you can install them.
In a scenario where you want to deploy a number of web applications and run their dependency managers, how could you run all of them in a systematic order.
One of the complexity is to ensure you get only your own top level dependencies. That way, you don recursively call development dependencies of your own dependencies.
Otherwise you might end up discovering dependency management manifests that are already been pulled by your own projects.
# Using this command
This command helps me find them and I can then run what?s required to pull them from their respective sources.
This command assumes the following:
1. Your code checkouts are in a flat repository layout (i.e. not nested).
2. Finds manifests for:
- NPM (nodejs),
- Composer (php),
- requirements.txt (Python), and
- git submodules
Replace "Oct 2" in the first grep pattern to be the date to view branch work from
Downloads this raw script https://github.com/git/git/blob/master/contrib/completion/git-completion.bash from Github, copies it to your home directory, autoloads it in ~/.bashrc and sources it.
Works even with spaces in filenames.
As an alias in .gitconfig:
editchanged = "!git status --porcelain | sed -ne 's/^ M //p' | tr '\\n' '\\0' | tr -d '\"' | xargs -0 vim"
You'll probably want to pass in the -rf options if you have to delete a directory or something.
Copy changed files from remote git repository, _including binary ones_, staged and unstaged alike. Note that this command doesn't handle deleted files properly.