https://github.com/johnantoni/git-notes
git notes
https://github.com/johnantoni/git-notes
Last synced: 7 months ago
JSON representation
git notes
- Host: GitHub
- URL: https://github.com/johnantoni/git-notes
- Owner: johnantoni
- Created: 2013-08-26T14:32:27.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2014-03-13T15:33:19.000Z (over 12 years ago)
- Last Synced: 2025-02-05T19:09:08.663Z (over 1 year ago)
- Size: 211 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GIT
## Installing GIT Hooks
$ cd .git
$ rm -fr hooks
$ git clone git://github.com/zoocasa/git-hooks.git hooks
## Common Development Tasks
### Squash Commits
git rebase -i HEAD~3
~3 = review last three commits
Do your changes, the first commit message will be the title one, the rest will be below it, sub headings.
Once done, you'll need to rewrite the remote's history to keep everything in-sync so force-push it.
git push origin branch-name --force
rewrite history on remote
### discard all changes
git checkout -- .
### List edits by who on what (blame)
git blame [filename]
### Pruning Branches
git fetch --prune
git prune
git gc --aggressive
### Fetching Remote Branches
git fetch --all
### Create a new Branch based on the current commit
git co -b [new-branch-name]
### Track Branch (git 1.8)
git branch -u origin/new-feature
### Amend a Commit
git commit -m 'initial commit'
git add forgotten_file
git commit --amend
### Ammend a Commit (rewriting remote branch's history)
git co HEAD~1
git commit -m 'forgotten file'
git push origin branch-name --force
### Get all Changes from Parent branch
Say you're on new-feature and you want to pull the changes from master
##### First make sure your local master is up-to-date
git co master
git pull --rebase -p
-p means prune any obsolete branches
##### Now checkout your new-feature branch and pull the changes from master
git co new-feature
git rebase master
When you rebase it will stop if there's merge conflicts introduced from master.
If you get any, fix them with your text editor then:
##### Check what's been changed:
git status
git diff
Add your resolutions:
git add .
Continue rebasing:
git rebase --continue
If nothing was changed with resolution:
git rebase --skip
Once resolved & rebased you will now be back on the new-feature branch with an updated commit history.
To push your changes to the branch you'll need to force-push as the history in the remote branch will be out of date.
git push -f origin new-feature
### Destroy your last commit?
If you accidentally committed something you wish you hadn't,
git reset --hard HEAD~1
rollback one commit
git push origin [branch-name] --force
force push your branch overwriting the remote and wiping that commit from existence
NOTE: best to do a git pull before even thinking about --force pushing your changes as you'll potentially wipe someone elses commits if you don't have them.
### When to do a rebase / force-push
* Before merging into the main branch
* When reviving an old branch
## Cherry Pick one commit into current branch
Find the commit id for the one you want to apply to the top of your current branch, then:
git cherry-pick [commit hash]
More [here](http://ariejan.net/2010/06/10/cherry-picking-specific-commits-from-another-branch/)
## Rollback Local to be same as Remote
git fetch origin
git reset --hard origin/master
## Commands
### git r
show current branch history
### git ra
show all history
### git push --set-upstream origin
*--set-upstream* sets what ref we'll be pushing to so we don't have to specify every time.
This won't have any effect as we've used [default=nothing] in our .gitconfig so we'll have to specify the ref on each push.
### git pull --rebase
Doing 'git pull' is fine but if you're working on a branch others are actively using this will add a merge message to the log messing up the log history. Using --rebase will do a pull then rebase and keep the log clean.
### git stash
Stash your un-committed changes
### git stash pop
Restore your stashed changes
### git stash list
List all stashed changes
### git stash pop[1]
Restore stashed change at location 1
### git merge --ff-only
Refuse to merge and exit with a non-zero status unless the current HEAD is already up-to-date or the merge can be resolved as a fast-forward.
### git branch -d
Delete local branch
### git push origin --delete
Delete remote branch
### git ri
Start interactive rebase
### git rebase --abort
Abort rebase
### git reset --soft
Does not touch the index file nor the working tree at all (but resets the head to , just like all modes do). This leaves all your changed files "Changes to be committed", as git status would put it.
### git reset --hard
Resets the index and working tree. Any changes to tracked files in the working tree since are discarded.
### git reset --hard HEAD~3
Rewind branch 3 commits back, destroying those commits
### git grep [search term]
Search committed code in a git repo http://stackoverflow.com/questions/2928584/how-to-grep-search-committed-code-in-the-git-history
### git blame [file]
See commit history for file.
### git branch -a
See both local and remote branches
### git branch -l
See local branches
### git branch -r
See remote branches
### git submodule add
Add submodule
git submodule add git@github.com:johnantoni/git-notes.git docs/git-notes
## Tools
* TIG[https://github.com/jonas/tig]
## Notes
### Rebase Types
p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like "squash", but discard this commit's log message
x, exec = run command (the rest of the line) using shell
## Links
* [revert to previous commit](http://stackoverflow.com/questions/4114095/git-revert-to-previous-commit-how)
* [25 Tips for Intermediate Git Users](http://andyjeffries.co.uk/articles/25-tips-for-intermediate-git-users)
* [GitX for OSX](https://github.com/rowanj/gitx)
Broken git pull location, edit .git/config
* [http://stackoverflow.com/questions/13030714/git-1-8-0-fatal-the-current-branch-master-has-multiple-upstream-branches-refu](http://stackoverflow.com/questions/13030714/git-1-8-0-fatal-the-current-branch-master-has-multiple-upstream-branches-refu)