Commit only part of a file’s changes in Git

You can use: git add –patch <filename> or for short: git add -p <filename> Git will break down your file into what it thinks are sensible “hunks” (portions of the file). It will then prompt you with this question: Stage this hunk [y,n,q,a,d,/,j,J,g,s,e,?]? Here is a description of each option: y stage this hunk for … Read more

Purging file from Git repo failed, unable to create new backup

You have already performed a filter-branch operation. After filter-branch, Git keeps refs to the old commits around, in case something goes wrong. You can find those in .git/refs/original/…. Either delete that directory and all files within, or use the -f flag to force Git to delete the old references. git filter-branch -f \ –index-filter ‘git … Read more

How to reference the initial commit?

Do not use git-log for scripting: use either git-rev-list, or git-log with specified custom format (–format=*<sth>* option). There is additional problem with your question: there can exist more than one such TAIL root commit (parentless commit) in a repository (even if we discount disconnected branches, such as ‘html’, ‘man’ and ‘todo’ in git.git repository). This … Read more

Remove commit from history

Once you push to the repo, you really don’t want to go about changing history. However, if you are absolutely sure that nobody has pulled/fetched from the repo since your offending commit, you have 2 options. If you want to remove the “bad” commit altogether (and every commit that came after that), do a git … Read more