Git
Basics
clone a repository
git clone git@github.com:entorb/rememberthemilk.git
perform a commit
git add . git commit -m "my commit message" git push
Re-apply .gitignore
see https://github.com/entorb/tools/blob/master/git-tools/git-gitignore-reapply.cmd
Branching
# create new branch git checkout -b history-change # del branch git checkout master git branch -d history-change
Rest branch to remote branch
from [1] Setting your branch to exactly match the remote branch can be done in two steps:
git fetch origin git reset --hard origin/master git push # or git push -f
Reverting
revert a commit
get hash of commit git log --oneline git revert <commit hash> # git push
revert local git to remote repository from [2]
git reset --hard HEAD git clean -f -d git pull
Chmod
set executable flag
git update-index --chmod=+x file
Git Settings
colorful output
git config color.ui true
log: one line per commit
git config format.pretty oneline
Error handling
Error:
git pull --tags origin master [rejected] ... (would clobber existing tag)
Fixed by updating local tags with remote tags
git fetch --tags -f
Tag handling
Delete a tag locally
git tag -d myTag
Delete a tag remotely
git push --delete origin myTag
Checking History
Display all commits that modified a certain file
git log --no-decorate --pretty=format:"%h%x09%ad%x09%an%x09%s" --date=iso -- data/de-districts/de-district_timeseries-02000.tsv # %x09 : tab
Modifiying History
Merge 2 repos
see https://github.com/entorb/tools/blob/master/git-tools/git-merge-2-repos.cmd
delete a dir from historiy using bfg
using bfg
https://github.com/entorb/tools/blob/master/git-tools/git-bfg-cleanup-delete-history-of-dir.cmd
delete complete commits history
First Method from [3]
# Check out to a temporary branch: git checkout --orphan TEMP_BRANCH # Add all the files: git add -A # Commit the changes: git commit -am "Initial commit" # Delete the old branch: git branch -D master # Rename the temporary branch to master: git branch -m master # Finally, force update to our repository: git push -f origin master
Second Method via "deleting .git folder" also from [4]
# Clone the project, e.g. `myproject` is my project repository: git clone https://github/heiswayi/myproject.git # Since all of the commits history are in the `.git` folder, we have to remove it: cd myproject # And delete the `.git` folder: rm -rf .git # Now, re-initialize the repository: git init git remote add origin https://github.com/heiswayi/myproject.git git remote -v # Add all the files and commit the changes: git add --all git commit -am "Initial commit" # Force push update to the master branch of our project repository: git push -f origin master
Alternative method:
https://www.willandskill.se/en/deleting-your-git-commit-history-without-removing-repo-on-github-bitbucket/
Notes of 2020
very nice tutorial: git - Der einfache Einstieg
Old notes
git init # create an empty git repository in the current folder # set some settings git config --global user.name "Torben Menke" git config --global user.email "torben.menke@XXX.de" git config --global color.ui auto git config -l # shows configuration git add somefile.txt # one file git add somefolder # one folder git add . # all git commit git commit -a -m "message" # commit all, message="message" git pull ssh://tmenke@[IP]/[PATH] master # edit # commit git push ssh://tmenke@[IP]/[PATH] master git log git log --pretty=oneline --abbrev-commit