this needs to be cleaned up
![]() |
(on Wikipedia)
https://www.git-scm.com/ [ 1 ] was http://git.or.cz
A version control system of some note.
I use it, not that I know what I'm doing.
See also:
- My git repository for git scripts
- Git on Windows
-
tig (text-mode interface for git)
TODO - learn how to do change reviewing
Repository hosting websites:
--
-
2018-12-13 - 2.11.0 on Windows 10 on Windows Subsystem for Linux on Debian 9.5
- 4.4.0-17134-Microsoft #471-Microsoft Fri Dec 07 2018 x86_64 GNU/Linux
- 2018-12-13 - 2.11.0 on Devuan_ascii_2.0.0-rc_i386_dvd-1
- 2016-03-29 - 2.6.2 on Slackware 14.1
-
2016-03-26 - 1.9.1 on Lubuntu 14.04.4 LTS
- 1 Tools
- 2 Quick tips
- 3 Identifying yourself
- 4 Tagging
- 5 Download everything fresh
- 6 Revisionism
- 6.1 Change the last commit message
- 6.2 Go back in time - checkout a previous version
- 6.3 Roll the repository back a little
- 6.4 Forgot to check in an old revision of a file
- 6.5 Remove all trace of a file
- 6.6 Change the "Author" entry in the changelog
- 6.7 Renaming/deleting tags on GitHub
- 6.8 Restore a file deleted from git
- 7 Repository maintenance - compression / optimization
- 8 Actually add files
- 9 Ignoring files
- 10 Synchronize clone with its repository file creation times
- 11 Compare local edits
- 12 Compare local edit to remote change
- 13 Split a directory into its own repository
- 14
git fsck
showsdangling tree
- 15 example
.gitattributes
- 16 Troubleshooting
- 16.1 Remove "warning: LF will be replaced by CRLF in"
- 16.2 Fix
ESC[33m
andESC[m
and restore colour - 16.3 Fix the default git push
- 16.4 "error: Your local changes to the following files would be overwritten by merge:"
- 16.5 readlink function not implemented
- 16.6
.git/config
hasurl =
with an email address as a username (contains an at (@
) symbol - 16.7
git gc
gives "suboptimal pack - out of memory
" - 16.8
git gc
gives rename errors
- 17 Resources
Tools ∞
-
gitk
- While rather awful, it lets you do at least basic things.
Quick tips ∞
-
2009-01-16 - Having trouble cloning a repository? I got
chdir
"permission denied" errors. I had to installgit-core
.- (distribution not recorded)
-
Check out a single remote file
git checkout origin -- FILENAME
Identifying yourself ∞
Stuff will go in .git/config
If you screw this up, even after the fact, see Change the "Author" entry in the changelog.
For only the current repository ∞
\git config --global user.email "you@example.com" \git config --global user.name "Your Name"
For all repositories that aren't specifically-set ∞
\git config --global user.email "you@example.com" \git config --global user.name "Your Name"
Tagging ∞
\git tag "v1.3" \git push --tags
This provides a new package to download.
Rename a tag ∞
I am told it is the following, but for me it only deleted the old tag!
OLD_TAG="some text" NEW_TAG="some text" git push origin refs/tags/"$OLD_TAG":refs/tags/"$NEW_TAG" :refs/tags/"$OLD_TAG" git tag -d "$OLD_TAG"
Download everything fresh ∞
Downloading everything fresh. Maybe after accepting a pull request.
\git pull git@github.com:spiralofhope/shoes-contrib.git master
Revisionism ∞
- git rewrite history - remove filenames from specific path? - Stack Overflow
-
- The BFG is a simpler, faster alternative to git-filter-branch for cleansing bad data out of your Git repository history
- The author is retarded:
-
You can rewrite history in Git - don't let Trump do it for real!
Trump's administration has lied consistently, to make people give up on ever
being told the truth. Don't give up: https://www.theguardian.com/us-news/trump-administration
Change the last commit message ∞
\git commit --amend
Change an older commit message ∞
Unexplored:
https://docs.github.com/en/github/committing-changes-to-your-project/changing-a-commit-message [ 2 ] was https://docs.github.com/en/free-pro-team@latest/github/committing-changes-to-your-project/changing-a-commit-message [ 3 ] was https://help.github.com/en/github/committing-changes-to-your-project/changing-a-commit-message
Go back in time - checkout a previous version ∞
\git log \git checkout <code>
to return:
\git pull origin HEAD
Roll back all files to a previous commit ∞
git reset --hard <tag/branch/commit id>
If you wish to commit that state, so remote repository also points to rolled back commit do:
git push <reponame> -f
You can also do something simple like roll back to the previous commit:
git reset --hard HEAD~1
Roll the repository back a little ∞
Screwed up a commit and want to roll back a little?
\git rebase -i HEAD^^
.. where the number of carats (^) is the number you wish to roll back.
Then within the editor, delete any lines you want to excise from git's history. Each line represents a particular commit.
Be aware that this can delete files from the disk.
Forgot to check in an old revision of a file ∞
See also https://stackoverflow.com/questions/3895453/how-do-i-make-a-git-commit-in-the-past
Well there's no easy way. It's probably doable but I can't find a solution.
The closest I get is an incomplete solution: https://web.archive.org/web/20181009092446/http://blog.xkoder.com:80/2009/06/06/git-tutorial-part-ii-sharpen-you-git-fu-with-10-more-commands/
Find the commit hash before the file you want to modify, then check it out.
\git checkout COMMIT_HASH
Make your changes, then commit them.
\git commit -a
FIXME ... then supposedly there's a way to propagate the changes back to the master's HEAD. Fucked if I know how. The above link doesn't actually explain that. I am disappoint.
Go back to the present.
\git checkout master
Remove all trace of a file ∞
Change the "Author" entry in the changelog ∞
For git log
, change the editor
field.
Renaming/deleting tags on GitHub ∞
Deleting using the GitHub UI:
- Visit your repository
-
Find the row:
Commits | Branch | Releases | Contributor
, clickreleases
- You will see a list of all releases.
- At the top-left,
Releases | Tags
, click Tags - Click on the name of one of the releases
-
At the top-right,
Edit release | Delete
Synchroninzing your github tag deletion to your local git repository:
git tag -l | xargs git tag -d git fetch
Renaming a tag in a local git repository:
NEW_TAG_NAME=newtag OLD_TAG_NAME=oldtag git tag $NEW_TAG_NAME $OLD_TAG_NAME git tag -d $OLD_TAG_NAME git push origin :refs/tags/$OLD_TAG_NAME git push --tags
Restore a file deleted from git ∞
List all deleted files ∞
\git log --diff-filter=D --summary
Un-commit a single deleted file ∞
\git checkout -- filename.ext
Roll back an individual file ∞
\git log filename.ext
\git checkout <revision> filename.ext
For example:
\git log filename.ext commit 875465be775031545f9c7f89as8025373df63e23 Author: AUTHORNAME Date: Sun Jul 19 01:20:11 2015 -0700 . commit 8409d2b3aaff1276c1266748397fe3d6e9576961 Author: AUTHORNAME Date: Thu Jul 2 10:54:37 2015 -0700 misc, theme updates, media locally cached git checkout 4d0f80012abfe9d074db841ae36f07f0722f31c8 -- filename.ext
Why there isn't a git checkout -1 -- filename.ext
- type command is beyond me. I think maybe that's HEAD~1
but I haven't tested this.
I was told the right command was git checkout <filename> -1
but that didn't work..
There is also git reset
See also:
- https://stackoverflow.com/questions/2733873/reverting-a-single-file-to-a-previous-version-in-git
- https://stackoverflow.com/questions/215718/how-can-i-reset-or-revert-a-file-to-a-specific-revision
-
https://thecodeartist.blogspot.com/2015/04/git-prevision-checkout-previous-version-of-file.html
- This does not work for me (git version 2.7.4)
Repository maintenance - compression / optimization ∞
I don't understand these things, but they do stuff and things and that's good. Probably.
\git fsck
\git gc
(gc
will fix shit that fsck
finds)
Actually add files ∞
I don't know what fucking idiot would have git add -A
not work as expected, but this seems to work:
\git rm --cached -r directory \git add directory
Ignoring files ∞
https://git-scm.com/docs/gitignore
$HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore
If you want to remove all trace of a file, including from git history, see Remove all trace of a file.
Synchronize clone with its repository file creation times ∞
https://github.com/tst2005/git-timesync/
(archived)
When you make a git clone the created file are the current date. This script allow you to change the file timestamp to the same than the repository one.
Compare local edits ∞
\git show HEAD:filename.ext | \wc --bytes
- Compare the change between commits
commit1="HEAD" commit2="HEAD^" filename="filename.ext" source=$( \git show "$commit1":"$filename" | \wc --bytes ) target=$( \git show "$commit2":"$filename" | \wc --bytes ) \echo "( $source - $target )" | \bc
Compare local edit to remote change ∞
Changes to all files ∞
\git diff
-
Difference between remote and local file
git diff origin/master -- FILENAME
- Ignore whitespace with
git diff -b origin/master -- FILENAME
-
Difference between two commits
- e.g. this commit and the previous one:
git diff HEAD HEAD^
- e.g. this commit and the previous one:
-
Difference between local and remote repositories
git diff master origin/master
If you use an external tool like Diffuse, then instead use git difftool
.
Changes to a specific file ∞
\git diff origin/master:./ -- README.md \git diff HEAD^:./ -- README.md \git diff stash@{0}:./ -- README.md \git diff 1A2B3C4D:./ -- README.md
Visually ∞
Not tested, vi is insane:
\git difftool
It will start your diff app automatically for each changed file.
Windows: If you did not set a diff app, you can do it like in the example below(I use Winmerge):
\git config --global merge.tool winmerge \git config --replace --global mergetool.winmerge.cmd \ "\"C:\Program Files (x86)\WinMerge\WinMergeU.exe\" -e -u -dl \"Base\" -dr \"Mine\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"" \git config --global mergetool.prompt false
Split a directory into its own repository ∞
2017-08-30
folder=my_folder branch=master \git filter-branch \ --prune-empty \ --subdirectory-filter "$folder" \ "$branch" \ ` # `
You may need to edit .git/config
to update url
or other settings.
If you intend to host this repository on GitHub, then follow their new repository creation documentation and see also GitHub's documentation on splitting a subfolder out into a new repository.
git fsck
shows dangling tree
∞
git fsck
This was seen after I did a Split a directory into its own repository.
I've now worked on that repository for some time now, without addressing this.
Failed solutions:
-
git gc
Notes:
- https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery
- https://stackoverflow.com/questions/16955523/git-broken-links-missing-dangling-trees
example .gitattributes
∞
*.lua filter=trimTrailingSpaces *.xml filter=trimTrailingSpaces *.toc filter=trimTrailingSpaces
Troubleshooting ∞
Remove "warning: LF will be replaced by CRLF in" ∞
\git config core.safecrlf false
Fix ESC[33m
and ESC[m
and restore colour ∞
\git config --global core.pager "less -r"
Fix the default git push ∞
Cloned something and want to fix its default push?
\git remote rm origin \git remote add origin git://github.com/spiralofhope/shoes.git
.. hrm, not working right, try editing .git/config
and changing the url
line to something like git@github.com:spiralofhope/random-shoes.git
"error: Your local changes to the following files would be overwritten by merge:" ∞
git checkout HEAD^ FILENAME
readlink function not implemented ∞
error: readlink("path/to/filename"): Function not implemented error: unable to index file path/to/filename fatal: updating files failed
git config core.symlinks true
instead of git config core.symlinks false
got rid of the error for me. Consequently, the symlinks I created using mklink in Windows were pushed without error, but when cloning the project again, the symlinks become text files that says where the original files are located instead of working as a real symlink.
Tested 2016-07-20 with 2.9.0.windows.1 - it seems to work.
.git/config
has url =
with an email address as a username (contains an at (@
) symbol ∞
If git push
fails because you're trying to use an email address as a username, which is set in your .git/config
file, then..
Tested 2019-09-05 with Git 2.11.0 using GitHub.
Use %40
instead of the @
in your email address. E.g. if your username is email@example.com
you would instead use email%40example.com
like so:
[remote "origin"] url = https://email%40example.com@github.com/githubusername/repository-name.git
git gc
gives "suboptimal pack - out of memory
" ∞
If doing a git gc
you get:
warning: suboptimal pack - out of memory fatal: Out of memory, malloc failed (tried to allocate 125098831 bytes) error: failed to run repack
\git config pack.windowMemory 256m
If you wish to avoid this problem in the future, try performing the git gc
after every significant change.
git gc
gives rename errors ∞
This will occur if you use sudo
or if you are trying to work with the files within Linux when they are hosted on Windows. This was reproduced on a Linux guest inside of a VirtualBox Windows 10 host, and fixed by performing the command from within Windows 10 in Windows Subsystem for Linux.
More notes.. I hate git.
Restructured.
Using an email address as a username in `.git/config`.
added notes on comparing different commits (contents and sizes)
Remove "warning: LF will be replaced by CRLF in"
Mo' git mo' problems.