git reset --hard origin/my-branch$ git tag new old
$ git tag -d old
$ git push origin new :old
$ git pull --prune --tags$ git branch -m <newname>If you rebase a branch and end up with conflicts on either of these files, first checkout the HEAD version of the file:
$ git checkout HEAD -- yarn.lock
$ git checkout HEAD -- Gemfile.lockThen followup with a yarn install or bundle install.
If you have a prior commit that you'd like to break up into multiple commits, you can rebase and reset:
$ git rebase -i head~3Change the commit to edit in the rebase window, save and exit. Then reset to undo the commit you are editing:
$ git reset head~1Now you can stage and commit until you are finished committing all of the files. Once you've finished creating your new commits, you can continue:
$ git rebase --continue$ git log develop..egl/my-feature-branchor, without merges:
$ git log --no-merges develop..egl/my-feature-branchYou can also show the changes with -p:
$ git log -p develop..egl/my-feature-branchThis is useful if you are thinking about creating a PR and you're curious how many files are going to end up in it:
$ git diff --name-status master..my-feature-branch$ git log -- path/to/file.txt
# look for the commit before the commit where the file was deleted (assuming you know)
$ git checkout commitish-sha -- path/to/file.txtFirst setup git to use the global gitignore from your home directory
$ git config --global core.excludesfile '~/.gitignore'Then add your global .gitignore
Here's a good explanation: https://stackoverflow.com/questions/38001038/how-to-undo-a-git-commit-amend/38002218
$ git reset --soft @{1}$ git reset --hard origin/features/mah-featureSometimes when rebasing master you get a conflict on a file and you just want to pull the version from master
During a rebase
- "ours" = master
- "theirs" = your branch
$ git checkout --ours somefile.txtYou can get a listing of remote branches with
$ git branch -aBut, this list might be very long and could include deleted branches. To remove them from the list
$ git remote prune origin$ git push -u origin HEADAfter you've navigated to a previous commit on a branch, to get back to the latest commit on that branch
$ git checkout -When doing a code review it might be nice to see a log of commits on a branch. This command shows the commits that exist on the feature branch that do not exist on master:
$ git cherry -v master features/my-awesome-featureSay the commit you want to edit is bbc643cd:
$ git rebase --interactive 'bbc643cd^'Change pick to edit for the commit.
Then make the edits you want to make.
Then amend the current commit:
$ git commit --all --amend --no-editAnd, finally, continue on with the rebase to finish up:
$ git rebase --continueThe first way you can do this is to just ammend the commit (provided it's the last commit):
$ git commit --amendIf the commit isn't the last commit, you need to rebase:
$ git rebase -i head~3This will open the last 3 commits in an interactive rebase. Each commit starts with the work pick. For the commit you want to change the message for, change pick to edit:
pick 0d7dd56 Moving test helpers out into support file
pick ec6e0c9 Adding in vue-router
reword 8f6b0ab Adding in debug unit testing
When you save this and close out of it, git will open the commit dialog for this commit again so you can edit the message.
Git keeps track of everything that happens to the repo in the reflog.
To view a list of events:
$ git reflogThe output of that command isn't super useful. To show output in git log format:
$ git log -g$ git filter-branch --tree-filter 'rm -f supersecretpass.txt' HEAD- Find the hash for the commit when you removed the file
- Enter this command:
$ git checkout 048ddf081^ -- path/to/file.rb$ git diff$ git diff --staged$ git difftool 3e11f62ad37b871f^!$ git diff 3ca00c2c847^!
# it would be better to say:
$ git show 3ca00c2c847$ git diff HEAD~5
# you could also say
$ git log -p -5$ git diff master bird$ git diff HEAD^ app/controllers/sites/corporate/pages_controller.rb$ git log --grep=maps$ git log --pretty=oneline
$ git log --oneline$ git log --pretty=oneline
$ git log --onelineThis is a great way to search for changes in the codebase.
$ git log -p
# then you can search for terms by hitting the "/" key$ git log --author='onehouse <elliot@onehouse.net>'$ git log --oneline --stat$ git log --oneline --graph$ git log --until=1.minute.ago$ git log --since=1.month.ago --until=2.weeks.ago$ git log -2$ git log --format='%aN' | sort -u$ git show f769bc31bdd --stat | grep '|.*[+]*-*$' | awk '{print $3}' | paste -sd+ - | bc$ git show f769bc31bdd --statThis resets to the upstream branch. Say you're on a branch features/cool-stuff, you can use this to set the local branch to what's on origin/features/cool-stuff:
$ git reset --hard @{u}You can also do this by manually specifying the remote branch name explicitly:
$ git reset --hard origin/feature/mips-331-#147895895$ git reset file.html$ git reset --soft HEAD^$ git reset --soft HEAD^^$ get reset --hard HEAD^$ git commit --amend -m "New message for commit"$ git remote show originYou can also do this with the branch command. This will show all branches remote and local:
$ git branch -aThen checkout a remote branch:
$ git checkout <branch-name>$ git remote -v
$ git pull force
$ git fetch --all
$ git reset --hard origin/branch$ git remote add origin https://github.com…$ git remote rm <name>Passing bad and good revisions to git bisect start
$ git bisect start HEAD e6be773
# <bad> <good>Auto running git bisect with a command
$ git bisect run zeus rspec ./spec/models/commercial_application_spec.rbTo quit a bisect session, enter:
$ git bisect reset$ git checkout -t origin/haml$ git branch -r$ git branch origin :weasel$ git remote show origin$ git remote prune origin$ git push origin staging:master$ git checkout -b my-feature-branch
# ... do some work and commit several times
$ git rebase master
$ git checkout master
$ git merge --squash my-feature-branch
$ git commit -m 'adding in my feature'$ git tag$ git checkout <tagname>$ git tag -a v0.0.3 -m "version 0.0.3"$ git push --tags$ git fetch$ git config --global color.ui true$ git config --list$ git config --global alias.st status
$ git config --global alias.mylog "log --pretty=format: '%h %s [%an]' --graph"$ git config --global branch.master.rebase true
$ git config --global branch.autosetuprebase always