Difference between revisions of "Git/hacks"
(adds simple pointer on removing contents from previous commit) |
(adds trace setting) |
||
Line 1: | Line 1: | ||
+ | Add <code>GIT_TRACE=1</code> to your command to see more of what's going on. (Note that there are no spaces and no semicolon.) | ||
+ | <source lang="bash"> | ||
+ | GIT_TRACE=1 git status | ||
+ | </source> | ||
+ | |||
See all the changes in color, but without any context lines, and without the leading +/-/<nowiki>[space]</nowiki> | See all the changes in color, but without any context lines, and without the leading +/-/<nowiki>[space]</nowiki> | ||
This makes it easy to grab changes and stuff them in another file for example. | This makes it easy to grab changes and stuff them in another file for example. |
Revision as of 14:27, 18 December 2015
Add GIT_TRACE=1
to your command to see more of what's going on. (Note that there are no spaces and no semicolon.)
GIT_TRACE=1 git status
See all the changes in color, but without any context lines, and without the leading +/-/[space] This makes it easy to grab changes and stuff them in another file for example.
git diff -U0 --color myfile | sed -r "s/^([^-+ ]*)[-+ ]/\\1/"
You forgot to add a file to the last commit? Just add it to the index, and commit with --amend
. Added a file that shouldn't be there? git rm
it. If you leave off the -m (message) option in the new commit, it will let you re-use the last commit message. This lets you "undo the last commit" and redo it right. You usually do not want to amend a commit if you've already pushed it to other repos, but if it's just local --amend
is awesome-sauce.
git add forgotten.php
git rm oops.txt
git commit --amend
git log --stat
What's the commit history? --stat
gives a nice view of what happened in the log.
git log --stat
How do you ignore a directory, but make an exception? What if you already added certain directories to git but want to stop tracking them now (ie. "take them out of version control")?
A combination of editting your .gitignore
file and git rm --cached
to the rescue. I had accidentally added and committed some files into git which should have been ignored because they are 3rd party files managed by Composer. I fixed my .gitignore
to track only what I want while ignoring a parent directory:
/nbproject/* # ignore everything in the 'vendor' directory /vendor/* # but don't ignore the 'eqt' directory !/vendor/eqt/
Then you simply remove all files from git's index, and add them back (only now adding them back will look to .gitignore for the corrected rules)
git rm -r --cached .
git add .
git commit -m 'ignoring vendor/*'
Tags[edit | edit source]
With git, you can just tag something with git tag foo
. This produces a 'lightweight' tag [1]. Use "annotated tags" whenever you want to know when something was tagged and who did it. Pass an empty message if you really don't care or need extra annotation.
git tag -am '' 'REL-1.0-alpha'