Sometimes, depending on the file system, Git may not pick up case changes in filenames. To fix this, do the following:
git mv OldFiLename.thing temp.file
git mv temp.file oldfilename.thing
git cherry-pick <commit id>
To count the number of lines added/edited between two commits or branches:
git diff --stat <commit or branch> <commit or branch>
To delete the branch locally:
git branch -d branch_name
To delete the branch on the remote:
git push origin --delete <branch_name>
or git push origin :<branch_name> for older git
git diff branch_1..branch_2
Git has a built-in web interface that can be started with the following:
git instaweb --httpd=webrick
To move the last commit(s) to another branch, first make a new branch (this will include the commits from the current branch):
git branch newbranch
Remove the unwanted commit(s) from the current branch (the command below just removes the latest commit):
git reset --hard HEAD^
To remove N
commits, you can use:
git reset --hard HEAD~N
Now newbranch
has the new commit(s) while the current branch no longer does.
git pull --rebase <remote> <branch>
git reset <filename>
To fully remove a submodule from a git repository:
# Remove from .gitmodules
git submodule deinit <submodule_name>
# Remove from repository
rm -rf .git/modules/<submodule_name>
For older versions of Git, you may need to do the following as well:
# Remove from config
git config --remove-section <submodule_name>
# Remove from working tree
git rm --cached <submodule_path>
git fetch origin
git reset --hard origin/master
Enter an interactive rebase session:
git rebase -i <commit id to start after>
In interactive mode, replace pick with squash for the commits to squash.
To undo the last commit, discarding the changes:
git reset --hard HEAD~1
To undo the last commit, keeping the changes:
git reset HEAD^
OR
git reset --soft HEAD~1