Published on

GIT Tips

Authors
  • avatar
    Name
    Timothy Blanks

Tooling

https://fork.dev/

Get file from diff beanch

  git show branch:file

rollback change

git checkout -- filename

undo last local commit

git reset HEAD~1

get latest for different branch

git fetch origin master:master

Pull main into current branch

git checkout <branch name>
git merge main

Generate a patch file

git diff >> ../env2.diff

Apply patch file

git apply ../env2.diff

Stash and keep

 git stash push --keep-index -m 'name it'

Branch diff

  git diff branch1..branch2

Tags

Find last tag

  git tag | grep v1.0 | sort -r | head -n 1

Push --followTags automatically

  git config --global push.followTags true

Push follow tags

  git push --follow-tags

Alias commands

https://diamantidis.github.io/2018/11/10/save-time-with-git-aliases

Reset head to previous commit

  git reset --hard f414f31
  git reset --soft HEAD@{1}
  git commit -m "Reverting to the state of the project at f414f31"

from https://stackoverflow.com/questions/9529078/how-do-i-use-git-reset-hard-head-to-revert-to-a-previous-commit

Remote

Get URL only

  git config --get remote.origin.url

Full output

Push to remote

  git push -u origin <branch>
  git remote show origin

Keep file in git but ignore future changes

That will ignore changes to that file, both local and upstream, until you decide to allow them again with:

git update-index --no-skip-worktree default_values.txt

You can get a list of files that are marked skipped with:

git ls-files -v . | grep ^S

https://stackoverflow.com/questions/4348590/how-can-i-make-git-ignore-future-revisions-to-a-file