Skip to content

Instantly share code, notes, and snippets.

@kurogane1031
Last active May 11, 2022 02:21
Show Gist options
  • Save kurogane1031/60bfe60401ad9480d1cbe1c8d20ab613 to your computer and use it in GitHub Desktop.
Save kurogane1031/60bfe60401ad9480d1cbe1c8d20ab613 to your computer and use it in GitHub Desktop.
GIT Tips for myself
Caution: This is not revert, and only do this for personal commits
### Steps
1. `git log`
2. get the hash
3. `git reset --hard <hash>
### (Alternative) Steps
1. `git log`
2. `git reset --hard HEAD~1` (This reset previous 1 commit)
git pull --rebase --autostash

Yes, just like that!

Steps

  1. Clone whatever repo into your local machine.
  2. Create new repository on your github account.
  3. git remote rename origin upstream
  4. git remote add origin URL_TO_GITHUB_REPO
  5. git push origin master

Additional information

  1. To update from original master git pull upstream master && git push origin master

Reference

Git push existing repo to a new and different remote repo server?

!! This is directly copied from the stack exchange !!

Method A: Cherry Pick changes from another branch one by one, or by ranges

  1. Press l and then o to get a list of other branches.
  2. Select the branch you want to cherry pick from.
  3. Move to the commit you need and press A followed by A again. You can also select the lines with the commit range you want with C-space and press A followed by A again.
  4. The status line will show you which commit you selected, e.g. feature/ABC~4
  5. Press Enter to apply changes.

Method B: Cherry Pick all changes from another branch

  1. Press A to choose the cherry pick mode.
  2. Press A again to apply and commit changes. Press a to only apply changes.
  3. Choose a branch to cherry pick changes from and press Enter.

Reference

How to easily cherry pick with magit?

Steps

  1. First, make sure to install tree 1.8.0 or newer.
  2. Then, within project root folder, run the following.
git ls-tree -r --name-only HEAD | tree --fromfile

Works like a charm. At least for me.

Reference

Have tree hide gitignored files

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