From Torben's Wiki
Revision as of 11:56, 11 December 2021 by Torben (talk | contribs) (→‎Reverting)
Jump to navigationJump to search


clone a repository

git clone

perform a commit

git add .
git commit -m "my commit message"
git push

Re-apply .gitignore



# 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


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


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


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


delete a dir from historiy using bfg

using bfg

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
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:

Notes of 2020

very nice tutorial: git - Der einfache Einstieg

Old notes

[5] [6]

git init # create an empty git repository in the current folder
# set some settings
git config --global "Torben Menke"
git config --global ""
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