If you’ve made a commit, but want to revert the commit and retain the file changes as unstaged, do the following: git reset –soft HEAD^ git reset HEAD
Category: Git
List all commits on all branches from single user in Git
To list the commits of a single user from all branches, use the following command: git log –pretty=format:”%ad:%an:%d:%B” –date=short –reverse –all –since=2.months.ago –author=Anthony
Gitignore not ignoring file
If after you’ve updated .gitignore to ignore a file and the changes are not being ignored, do the following: git rm /path/to/your/file –cached This will remove the file from the repository, but not from the file system.
GIT: Find when a specific string was introduced to a branch
To find when a specific line of code was added to a branch with git, run the following: git log -S “your-string-here” –source –all –stat
Git – diff (compare) the same file on different branches
If you want to see the difference between the same file on separate branches, use the following snippet at the CLI: git diff branch1 branch2 — your-file.ext
Git – move accidental commits to a different branch
If you’ve been working on a common staging branch when you thought you were working on a personal feature branch, you can move your work by doing the following: git checkout feature_branch git cherry-pick SHA (Do this for each commit on the mistaken branch) git checkout staging git reset –hard HEAD~n (where n = the […]
Git – list commits in topic branch that are not within the master branch
git log topic ^master –no-merges This will list all commits within the topic branch that are not found within the master branch. I needed this to cherry-pick specific commits out of a working feature branch when I mistakenly rebased against a common staging branch.