How to compare / diff a file across two branches.
git diff branch1 master -- super-styles.css
Quick steps to squash commits without having to rebase.
If you’re working on a feature branch for example; this method will let you squash all commits into one as you merge them into another branch.
- Merge master into the feature branch
// from branch my-feature (assume has 10 new commits)
git merge master// fix conflicts & commit
2. Squash my-feature`
into master`
git checkout master
git merge --squash my-feature
3. Commit changes as one.
git commit -m "Adds my-feature to master"
4. Result
All 11 commits appear as 1 in the master branch history.
Quick-fire instructions to bring specific changes to another branch.
Run the command on the branch you want to bring code into:
git checkout --patch origin/[branch] [folder/path]
This will give you a list of “hunks” in your Vim editor.
Go through each hunk and choose which ones you want & which you don't.
Or manually edit if you partially want it.
Quick-fire instructions to cherry-pick only certain files from a commit.
Get the commit
git cherry-pick -n <commit>
Unstage everything
git reset HEAD
Stage the modifications you want to keep
git add <path>
Make the work tree match the index
# (do this from the top level of the repo)
git checkout .
Done!