In the life of every developer regardless of experience level, comes a day when she needs to get out of or resolve an awkward git situation. In this series, I'm going to share some simple yet life-saving git commands that are both easy to learn and vital to your day-to-day version control ops.
1. undo the first commit ( assuming there is only one commit in the history)
git update-ref -d HEAD
2. undo the last (n) commits and return the changed files to staging area
git reset --soft HEAD~n
3. print the number of commits on all branches grouped by authors
git shortlog -s -n --all
p.s - yes Jayson, that's how I found out that I've done more commits than you. Take that.
4. undo a pushed commit in the remote repository, on master branch
git push origin +{commit-hash}^:master
5. See all the upstream repository urls, where you're 'pushing' your code.
git remote -v
6. remove a file from the staging area
git reset <file_name>
7. remove all files inside a folder from the staging area
git reset <folder_name>/
8. ignore changes to already tracked files
git update-index --assume-unchanged <file>
another alternative :
git update-index --skip-worktree <file>
read more on assume-unchanged vs. skip-worktree
9. undo last tip: start tracking files again
git update-index --no-assume-unchanged [<file> ...]
10. show list of tags, sorted by date descendingly
git tag --sort=-creatordate
Top comments (4)
The second part, I need it, I need it bad.
sure @dinniej! stay tuned
@dinniej there you go, part 2 dev.to/farhadfaghihi/git-survival-...
Great