<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://entorb.net//wiki/index.php?action=history&amp;feed=atom&amp;title=Git</id>
	<title>Git - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://entorb.net//wiki/index.php?action=history&amp;feed=atom&amp;title=Git"/>
	<link rel="alternate" type="text/html" href="https://entorb.net//wiki/index.php?title=Git&amp;action=history"/>
	<updated>2026-05-06T10:29:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://entorb.net//wiki/index.php?title=Git&amp;diff=5277&amp;oldid=prev</id>
		<title>Torben: /* Modifiying History */</title>
		<link rel="alternate" type="text/html" href="https://entorb.net//wiki/index.php?title=Git&amp;diff=5277&amp;oldid=prev"/>
		<updated>2025-07-07T02:46:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Modifiying History&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:Coding]]&lt;br /&gt;
&lt;br /&gt;
==Git Basics==&lt;br /&gt;
===Basics===&lt;br /&gt;
====clone a repository====&lt;br /&gt;
 git clone git@github.com:entorb/rememberthemilk.git&lt;br /&gt;
&lt;br /&gt;
====perform a commit====&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit -m &amp;quot;my commit message&amp;quot;&lt;br /&gt;
 git push&lt;br /&gt;
&lt;br /&gt;
===Git Settings===&lt;br /&gt;
&lt;br /&gt;
==== !!! End of Line !!! ====&lt;br /&gt;
Force Git for Windows to use Linux end of line: LF (\n) instead of CRLF (\r\n)&lt;br /&gt;
 git config --global core.autocrlf false&lt;br /&gt;
 git config --global core.eol lf&lt;br /&gt;
&lt;br /&gt;
To use git to fix bad line endings, add a .gitattributes file to the repo with this contents:&lt;br /&gt;
 * text=auto eol=lf&lt;br /&gt;
&lt;br /&gt;
====colorful output====&lt;br /&gt;
 git config color.ui true&lt;br /&gt;
&lt;br /&gt;
====log: one line per commit====&lt;br /&gt;
 git config format.pretty oneline&lt;br /&gt;
&lt;br /&gt;
===Branching===&lt;br /&gt;
 # create new branch&lt;br /&gt;
 git checkout -b history-change&lt;br /&gt;
 # del branch&lt;br /&gt;
 git checkout main&lt;br /&gt;
 git branch -d history-change&lt;br /&gt;
&lt;br /&gt;
====Rename branch master to main====&lt;br /&gt;
1. at github.com in the settings of the repo, rename the default branch name, for example at https://github.com/entorb/tools/settings/branches&lt;br /&gt;
&lt;br /&gt;
2. update in local repo&lt;br /&gt;
 git branch -m master main&lt;br /&gt;
 git fetch origin&lt;br /&gt;
 git branch -u origin/main main&lt;br /&gt;
 git remote set-head origin -a&lt;br /&gt;
&lt;br /&gt;
3. set default branch name in local git&lt;br /&gt;
 git config --global init.defaultBranch main&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
===Reports===&lt;br /&gt;
====Git Log====&lt;br /&gt;
 git log&lt;br /&gt;
 git log --pretty=oneline --abbrev-commit&lt;br /&gt;
 &lt;br /&gt;
 # list commits including the change summary, e.g. 1 file changed, 16 insertions(+), 2 deletions(-)&lt;br /&gt;
 git log --date=short --pretty=format:&amp;quot;%cd %h %s&amp;quot; --shortstat&lt;br /&gt;
&lt;br /&gt;
====Git Rev-list====&lt;br /&gt;
 # Get the total commits by week&lt;br /&gt;
 git rev-list --count HEAD --since=4.week&lt;br /&gt;
 git rev-list --count main --since=&amp;quot;Dec 1 2021&amp;quot; --before=&amp;quot;Jan 3 2022&amp;quot;&lt;br /&gt;
====Report of merges====&lt;br /&gt;
 var1&lt;br /&gt;
 git --no-pager log --merges --pretty=format:&amp;#039;MyRepoName	%cs    %ae    %s&amp;#039; | grep -v &amp;#039;dependabot&amp;#039; &amp;gt;&amp;gt; ../git-merge-report.csv&lt;br /&gt;
 var2&lt;br /&gt;
 git --no-pager log --grep=&amp;#039;#&amp;#039; --pretty=format:&amp;#039;MyRepoName	%cs	%ae	%s&amp;#039; --after 2022-01-01 &amp;gt;&amp;gt; ../git-merge-report.csv&lt;br /&gt;
 # note: in one repo the &amp;#039;--merges&amp;#039; flag did not find all merge PRs, so using --grep=&amp;#039;#&amp;#039; instead&lt;br /&gt;
&lt;br /&gt;
====Checking History====&lt;br /&gt;
Display all commits that modified a certain file&lt;br /&gt;
 git log --no-decorate --pretty=format:&amp;quot;%h%x09%ad%x09%an%x09%s&amp;quot; --date=iso -- data/de-districts/de-district_timeseries-02000.tsv&lt;br /&gt;
 # %x09 : tab&lt;br /&gt;
&lt;br /&gt;
===Modifiying History===&lt;br /&gt;
&lt;br /&gt;
====Merge 2 repos====&lt;br /&gt;
see https://github.com/entorb/tools/blob/main/git-tools/git-merge-2-repos.cmd&lt;br /&gt;
&lt;br /&gt;
====delete a dir from historiy using git-filter-repo====&lt;br /&gt;
preferred as of 2022 history cleanup using [https://github.com/newren/git-filter-repo git-filter-repo]&lt;br /&gt;
 pip install git-filter-repo&lt;br /&gt;
 git clone xxx&lt;br /&gt;
 cd xxx&lt;br /&gt;
 # backup .git/config&lt;br /&gt;
 cp .git/config ../config&lt;br /&gt;
 git-filter-repo --prune-empty always --invert-paths --path draft --path old --path maps/out&lt;br /&gt;
 # restore .git/config&lt;br /&gt;
 cp ../config .git/config&lt;br /&gt;
 &lt;br /&gt;
 git reflog expire --expire=now --all&lt;br /&gt;
 git gc --prune=now --aggressive&lt;br /&gt;
 &lt;br /&gt;
 git push -f&lt;br /&gt;
&lt;br /&gt;
to remove certain files matching a glob from history&lt;br /&gt;
 git-filter-repo --prune-empty always --invert-paths --path-glob &amp;quot;*.creds&amp;quot; --path-glob &amp;quot;data/*/*.json&amp;quot;&lt;br /&gt;
&lt;br /&gt;
afterwards revert your local repo to the remote one&lt;br /&gt;
 git fetch origin&lt;br /&gt;
 git reset --hard origin/main&lt;br /&gt;
 git pull&lt;br /&gt;
&lt;br /&gt;
==== combine changes to README.md etc into single commit ====&lt;br /&gt;
see https://github.com/entorb/tools/blob/main/git-tools/git-hist-combine.sh&lt;br /&gt;
&lt;br /&gt;
====delete a dir from historiy using bfg====&lt;br /&gt;
note: better use git-filter-rep (see above)&lt;br /&gt;
&lt;br /&gt;
using [https://rtyley.github.io/bfg-repo-cleaner/ bfg]&lt;br /&gt;
 https://github.com/entorb/tools/blob/main/git-tools/git-bfg-cleanup-delete-history-of-dir.cmd&lt;br /&gt;
 git reflog expire --expire=now --all&lt;br /&gt;
 git gc --prune=now --aggressive&lt;br /&gt;
&lt;br /&gt;
====squash/merge old commits====&lt;br /&gt;
 git rebase -i --root&lt;br /&gt;
 # this opens a list of all commits in you editor&lt;br /&gt;
 # replace pick by squash for the ones to&lt;br /&gt;
&lt;br /&gt;
====delete complete commits history====&lt;br /&gt;
First Method from [https://gist.github.com/heiswayi/350e2afda8cece810c0f6116dadbe651]&lt;br /&gt;
 # Check out to a temporary branch:&lt;br /&gt;
 git checkout --orphan TEMP_BRANCH&lt;br /&gt;
 # Add all the files:&lt;br /&gt;
 git add -A&lt;br /&gt;
 # Commit the changes:&lt;br /&gt;
 git commit -am &amp;quot;Initial commit&amp;quot;&lt;br /&gt;
 # Delete the old branch:&lt;br /&gt;
 git branch -D main&lt;br /&gt;
 # Rename the temporary branch to main:&lt;br /&gt;
 git branch -m main&lt;br /&gt;
 # Finally, force update to our repository:&lt;br /&gt;
 git push -f origin main&lt;br /&gt;
&lt;br /&gt;
Second Method via &amp;quot;deleting .git folder&amp;quot; also from [https://gist.github.com/heiswayi/350e2afda8cece810c0f6116dadbe651]&lt;br /&gt;
 # Clone the project, e.g. `myproject` is my project repository:&lt;br /&gt;
 git clone https://github/heiswayi/myproject.git&lt;br /&gt;
 # Since all of the commits history are in the `.git` folder, we have to remove it:&lt;br /&gt;
 cd myproject&lt;br /&gt;
 # And delete the `.git` folder:&lt;br /&gt;
 rm -rf .git&lt;br /&gt;
 # Now, re-initialize the repository:&lt;br /&gt;
 git init&lt;br /&gt;
 git remote add origin https://github.com/heiswayi/myproject.git&lt;br /&gt;
 git remote -v&lt;br /&gt;
 # Add all the files and commit the changes:&lt;br /&gt;
 git add --all&lt;br /&gt;
 git commit -am &amp;quot;Initial commit&amp;quot;&lt;br /&gt;
 # Force push update to the main branch of our project repository:&lt;br /&gt;
 git push -f origin main&lt;br /&gt;
&lt;br /&gt;
Alternative method:&amp;lt;br&amp;gt;&lt;br /&gt;
https://www.willandskill.se/en/deleting-your-git-commit-history-without-removing-repo-on-github-bitbucket/&lt;br /&gt;
&lt;br /&gt;
==Hacks==&lt;br /&gt;
=== Merge GitHub Dependabot PRs ===&lt;br /&gt;
 # switch to main branche and pull updates&lt;br /&gt;
 current_branch=$(git branch --show-current)&lt;br /&gt;
 if [ &amp;quot;$current_branch&amp;quot; != &amp;quot;main&amp;quot; ]; then&lt;br /&gt;
 	echo &amp;quot;branch was: $current_branch&amp;quot;&lt;br /&gt;
 	git checkout main&lt;br /&gt;
 fi&lt;br /&gt;
 git pull&lt;br /&gt;
 &lt;br /&gt;
 # update origin&lt;br /&gt;
 git fetch origin&lt;br /&gt;
 &lt;br /&gt;
 # list all branches that start with &amp;quot;dependabot/&amp;quot; but not &amp;quot;springframework&amp;quot; and save to c:/tmp/dependabot-branches.txt&lt;br /&gt;
 git branch -r | grep /dependabot/ | grep -v springframework &amp;gt;c:/tmp/dependabot-branches.txt&lt;br /&gt;
 # create empty file&lt;br /&gt;
 echo &amp;quot;&amp;quot; &amp;gt;c:/tmp/dependabot-changes.txt&lt;br /&gt;
 &lt;br /&gt;
 while read -r branch; do&lt;br /&gt;
 	# remove &amp;quot;origin/&amp;quot; from the branch name&lt;br /&gt;
 	branch_name=&amp;quot;${branch#origin/}&amp;quot;&lt;br /&gt;
 	echo &amp;quot;# $branch_name&amp;quot;&lt;br /&gt;
 	echo &amp;quot;# $branch_name&amp;quot; &amp;gt;&amp;gt;c:/tmp/dependabot-changes.txt&lt;br /&gt;
 	# switch to branch and pull latest version&lt;br /&gt;
 	git checkout &amp;quot;$branch_name&amp;quot;&lt;br /&gt;
 	git pull&lt;br /&gt;
 	# show changes to file pom.xml only&lt;br /&gt;
 	git diff main --unified=0 pom.xml &amp;gt;&amp;gt;c:/tmp/dependabot-changes.txt&lt;br /&gt;
 	echo &amp;quot;&amp;quot;&lt;br /&gt;
 	echo &amp;quot;&amp;quot; &amp;gt;&amp;gt;c:/tmp/dependabot-changes.txt&lt;br /&gt;
 done &amp;lt;c:/tmp/dependabot-branches.txt&lt;br /&gt;
 &lt;br /&gt;
 # back to main branch&lt;br /&gt;
 git checkout main&lt;br /&gt;
 &lt;br /&gt;
 # filter on changes only&lt;br /&gt;
 grep -e &amp;#039;^[#\+\-] &amp;#039; c:/tmp/dependabot-changes.txt &amp;gt;c:/tmp/dependabot-changes-filtered.txt&lt;br /&gt;
&lt;br /&gt;
===Cleanup===&lt;br /&gt;
====Remove branch not (any more) on main====&lt;br /&gt;
prunes tracking branches not on the remote.&lt;br /&gt;
from https://stackoverflow.com/posts/28464339/timeline&lt;br /&gt;
 git remote prune origin &lt;br /&gt;
list branches that have been merged into the current branch.&lt;br /&gt;
 git branch --merged&lt;br /&gt;
&lt;br /&gt;
===Reverting===&lt;br /&gt;
&lt;br /&gt;
====reset to a commit====&lt;br /&gt;
 get hash of commit&lt;br /&gt;
 git log --oneline&lt;br /&gt;
 git reset --hard HEAD~1&lt;br /&gt;
 # git push -f&lt;br /&gt;
&lt;br /&gt;
====revert a commit====&lt;br /&gt;
 get hash of commit&lt;br /&gt;
 git log --oneline&lt;br /&gt;
 git revert &amp;lt;commit hash&amp;gt;&lt;br /&gt;
 # git push -f&lt;br /&gt;
&lt;br /&gt;
====Reset branch to remote branch====&lt;br /&gt;
from [https://stackoverflow.com/posts/1628334/timeline] Setting your branch to exactly match the remote branch can be done in two steps:&lt;br /&gt;
 git fetch origin&lt;br /&gt;
 git reset --hard origin/main&lt;br /&gt;
 # git push -f&lt;br /&gt;
&lt;br /&gt;
====Fixing/Overwriting authors/emails====&lt;br /&gt;
list authors&lt;br /&gt;
 git shortlog -sn --all&lt;br /&gt;
 git log --pretty --author=&amp;quot;my@mail.com&amp;quot;&lt;br /&gt;
perform the history rewrite using global git config &lt;br /&gt;
(from https://stackoverflow.com/questions/750172/how-do-i-change-the-author-and-committer-name-email-for-multiple-commits/1320317#1320317) &lt;br /&gt;
 git rebase -r --root --exec &amp;quot;git commit --amend --no-edit --reset-author&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===Squashing===&lt;br /&gt;
Squash last 3 commits&lt;br /&gt;
 git reset --soft HEAD~3 &amp;amp;&amp;amp;&lt;br /&gt;
 git commit&lt;br /&gt;
&lt;br /&gt;
===revert local git to remote repository===&lt;br /&gt;
from [https://stackoverflow.com/posts/5361169/timeline]&lt;br /&gt;
 git reset --hard HEAD&lt;br /&gt;
 git clean -f -d&lt;br /&gt;
 git pull&lt;br /&gt;
&lt;br /&gt;
===GIT Commit to an existing Tag===&lt;br /&gt;
from https://gist.github.com/danielestevez/2044589&lt;br /&gt;
 1) Create a branch with the tag&lt;br /&gt;
 	git branch {tagname}-branch {tagname}&lt;br /&gt;
 	git checkout {tagname}-branch&lt;br /&gt;
 &lt;br /&gt;
 2) Include the fix manually if it&amp;#039;s just a change .... &lt;br /&gt;
 	git add .&lt;br /&gt;
 	git ci -m &amp;quot;Fix included&amp;quot;&lt;br /&gt;
     or cherry-pick the commit, whatever is easier&lt;br /&gt;
 	git cherry-pick  {num_commit}&lt;br /&gt;
 	&lt;br /&gt;
 3) Delete and recreate the tag locally&lt;br /&gt;
 	git tag -d {tagname}&lt;br /&gt;
 	git tag {tagname}&lt;br /&gt;
 &lt;br /&gt;
 4) Delete and recreate the tag remotely&lt;br /&gt;
 	git push origin :{tagname} // deletes original remote tag&lt;br /&gt;
 	git push origin {tagname} // creates new remote tag&lt;br /&gt;
 		&lt;br /&gt;
 5)  Update local repository with the updated tag (suggestion by @wyattis)&lt;br /&gt;
 	git fetch --tags&lt;br /&gt;
 &lt;br /&gt;
 This is based on https://gist.github.com/739288 thanks to nickfloyd for it&lt;br /&gt;
&lt;br /&gt;
====Chmod====&lt;br /&gt;
set executable flag. see [https://stackoverflow.com/questions/21691202/how-to-create-file-execute-mode-permissions-in-git-on-windows]&lt;br /&gt;
 git update-index --chmod=+x file&lt;br /&gt;
&lt;br /&gt;
===Error handling===&lt;br /&gt;
Error:&lt;br /&gt;
 git pull --tags origin main&lt;br /&gt;
 [rejected] ... (would clobber existing tag)&lt;br /&gt;
Fixed by updating local tags with remote tags&lt;br /&gt;
 git fetch --tags -f&lt;br /&gt;
&lt;br /&gt;
===Tag handling===&lt;br /&gt;
Delete a tag locally&lt;br /&gt;
 git tag -d myTag&lt;br /&gt;
Delete a tag remotely&lt;br /&gt;
 git push --delete origin myTag&lt;br /&gt;
&lt;br /&gt;
===Clean up via Garbage Collector===&lt;br /&gt;
 git reflog expire --expire=now --all&lt;br /&gt;
 git gc --prune=now --aggressive&lt;br /&gt;
&lt;br /&gt;
==Scripts==&lt;br /&gt;
===Re-apply .gitignore===&lt;br /&gt;
see https://github.com/entorb/tools/blob/main/git-tools/git-gitignore-reapply.cmd&lt;br /&gt;
 REM Remove everything from the git index in order to refresh your git repository:&lt;br /&gt;
 git rm -r --cached .&lt;br /&gt;
 REM Add everything back into the repo:&lt;br /&gt;
 git add .&lt;br /&gt;
 git commit -m &amp;quot;.gitignore re-applied&amp;quot;&lt;br /&gt;
 git status&lt;br /&gt;
 pause&lt;br /&gt;
 git push&lt;br /&gt;
&lt;br /&gt;
===pull on all repos===&lt;br /&gt;
 for D in $(ls -d */); do&lt;br /&gt;
 	echo === $D ===&lt;br /&gt;
 	cd $D&lt;br /&gt;
 	# git status&lt;br /&gt;
 	current_branch=$(git branch --show-current)&lt;br /&gt;
 	if [ &amp;quot;$current_branch&amp;quot; != &amp;quot;master&amp;quot; ] &amp;amp;&amp;amp; [ &amp;quot;$current_branch&amp;quot; != &amp;quot;main&amp;quot; ]; then&lt;br /&gt;
 		echo &amp;quot;branch was: $current_branch&amp;quot;&lt;br /&gt;
 		git checkout main&lt;br /&gt;
 		if [ $(git branch --show-current) != &amp;quot;main&amp;quot; ]; then&lt;br /&gt;
 			git checkout master&lt;br /&gt;
 		fi&lt;br /&gt;
 	fi&lt;br /&gt;
 	git pull --force&lt;br /&gt;
 	cd ..&lt;br /&gt;
 done &lt;br /&gt;
 read -p &amp;quot;Enter to close&amp;quot;&lt;br /&gt;
&lt;br /&gt;
===revert on all repos===&lt;br /&gt;
 for D in $(ls -d */); do&lt;br /&gt;
 	echo === $D ===&lt;br /&gt;
 	cd $D&lt;br /&gt;
 	current_branch=$(git branch --show-current)&lt;br /&gt;
 	if [ &amp;quot;$current_branch&amp;quot; != &amp;quot;main&amp;quot; ]; then&lt;br /&gt;
 		echo &amp;quot;branch was: $current_branch&amp;quot;&lt;br /&gt;
 		git checkout main&lt;br /&gt;
 	fi&lt;br /&gt;
 	git fetch origin&lt;br /&gt;
 	git reset --hard origin/main&lt;br /&gt;
 	git pull&lt;br /&gt;
 	cd ..&lt;br /&gt;
 done &lt;br /&gt;
 read -p &amp;quot;Enter to close&amp;quot;&lt;br /&gt;
&lt;br /&gt;
==GitHub.com Tipps==&lt;br /&gt;
===create PR for another fork===&lt;br /&gt;
* on github.com propose an edit for 1 file&lt;br /&gt;
* this creates a branch in our repo based on the fork, called patch-1 or similar&lt;br /&gt;
* rename the branch at `github.com/&amp;lt;your name&amp;gt;/&amp;lt;your repo&amp;gt;/branches/yours`&lt;br /&gt;
* now you can locally pull from your main to fetch the new fork and locally add more modifications&lt;br /&gt;
* I suggest keeping &amp;quot;unmodified&amp;quot; base-branches of other forks, so easily create new PRs and branches based on them&lt;br /&gt;
* to update the fork from he fork&amp;#039;s main, use github.com&lt;br /&gt;
&lt;br /&gt;
===Copy commit from parent/upstream repo to forked repo===&lt;br /&gt;
ensure that the parent repo is listed as upstream:&lt;br /&gt;
 git remote -v&lt;br /&gt;
 git fetch upstream&lt;br /&gt;
 # Create new branch&lt;br /&gt;
 git checkout -b copy-commit-branch&lt;br /&gt;
 git cherry-pick &amp;lt;commit-hash&amp;gt;&lt;br /&gt;
 # Resolve conflicts (if any):&lt;br /&gt;
 git cherry-pick --continue&lt;br /&gt;
 git push origin copy-commit-branch&lt;br /&gt;
 # Finally create a pull request&lt;br /&gt;
&lt;br /&gt;
Short version&lt;br /&gt;
 git fetch upstream&lt;br /&gt;
 git cherry-pick &amp;lt;commit-hash&amp;gt;&lt;br /&gt;
 git push&lt;br /&gt;
&lt;br /&gt;
==Notes of 2020==&lt;br /&gt;
very nice tutorial: [https://rogerdudler.github.io/git-guide/index.de.html git - Der einfache Einstieg]&lt;br /&gt;
&lt;br /&gt;
==Old notes==&lt;br /&gt;
[http://www.ralfebert.de/blog/tools/visual_git_tutorial_1/]&lt;br /&gt;
[http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html]&lt;br /&gt;
&lt;br /&gt;
 git init # create an empty git repository in the current folder&lt;br /&gt;
 # set some settings&lt;br /&gt;
 git config --global user.name &amp;quot;Torben Menke&amp;quot;&lt;br /&gt;
 git config --global user.email &amp;quot;torben.menke@XXX.de&amp;quot;&lt;br /&gt;
 git config --global color.ui auto&lt;br /&gt;
 git config -l # shows configuration&lt;br /&gt;
 &lt;br /&gt;
 git add somefile.txt # one file&lt;br /&gt;
 git add somefolder # one folder&lt;br /&gt;
 git add . # all&lt;br /&gt;
 &lt;br /&gt;
 git commit &lt;br /&gt;
 git commit -a -m &amp;quot;message&amp;quot; # commit all, message=&amp;quot;message&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
 git pull ssh://tmenke@[IP]/[PATH] main&lt;br /&gt;
 # edit&lt;br /&gt;
 # commit&lt;br /&gt;
 git push ssh://tmenke@[IP]/[PATH] main&lt;br /&gt;
 &lt;br /&gt;
 git log&lt;br /&gt;
 git log --pretty=oneline --abbrev-commit&lt;/div&gt;</summary>
		<author><name>Torben</name></author>
	</entry>
</feed>