Skip to content

Instantly share code, notes, and snippets.

@r-lyeh-archived
Last active March 28, 2016 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r-lyeh-archived/e0e48440b9d22c94569d to your computer and use it in GitHub Desktop.
Save r-lyeh-archived/e0e48440b9d22c94569d to your computer and use it in GitHub Desktop.
git-tips

Git tree command

git config --global alias.tree "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

git tree
* c3aee36 - (HEAD -> master, tag: DAY01, origin/master, origin/HEAD) '' (2 minutes ago) <r-lyeh>
* 5c978e9 - Initial commit (4 minutes ago) <r-lyeh>

Rollback all but the first commit

// http://stackoverflow.com/questions/16499908/how-to-roll-back-git-repo-to-first-commit-and-delete-all-history

To do that, you'd first find the SHA1 of the first commit, for example:

% git rev-list --max-parents=0 --abbrev-commit HEAD
aa8119f

...and then run either

% git reset aa8119f

...or

% git reset --hard aa8119f

...depending on whether you want to preserve or discard all the changes made since that initial commit. (The above assumes that you have only one branch. If not, you'll also have to delete any other branches you have with git branch -d .)

Finally, you'd run

% git push -f

(I hope that you realize that git push -f is a no-no whenever you're pushing to a repo that is shared with others.)

Unfortunately, as already explained, this approach does not delete all the history.

If this is something you'll want to do often, I'd recommend that, immediately after git init, you run something like

% git commit --allow-empty --allow-empty-message -m ''
% git tag -a -m '' ROOT

This will put an empty commit at the root of your history, and tag it with a tag named ROOT. Then you can do something like

% git reset ROOT

or

% git reset --hard ROOT

to bring you back to that first empty commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment