Stash local changes
git stash --include-untrackedgit reset --hard FETCH_HEADAdd a new commit, that undoes the changes added by the commit at HEAD. Can then be pushed to the remote repo without messing with other peoples commit histories.
git revert HEADUse git reflog to look back in time
git reflogFind a commit hash just before you stuffed something up, and checkout
git checkout [commit hash]Bring the head to this commit
git switch -Make sure this location has the correct state and history that you want. … if so
git reset --hard [commit hash]If you are happy with your location and changes, then do a force push so the remote is up to date
git push -fRemoves the most recent commit
git reset HEAD~Finish changes in branch Make pr See conflicts Rebase and solve conflicts in pr branch
git push --force # in pr branchIf someone else is on the same branch, ask what to do - git force push will affect them.
https://www.bryanbraun.com/2019/02/23/editing-a-commit-in-an-interactive-rebase/
git rebase -i HEAD~1 # where 1 is the number of commits back you go, it can also be a shaChange a commit to edit
git reset --soft HEAD~ # to remove commit, but keep changes to editCommit the fixed changes, then run
git rebase --continueIf the previous changes are on the remote, then do
git push -fTo rewrite the edited commit on the remote. Otherwise,
git push # is fineMake the diff file Go to github pr url and add ‘.diff’ Curl the url
Apply the patch with reject
git apply --reject --whitespace=fix ../tmp.diffMake the diff file Go to github pr url and add ‘.diff’ Curl the url
Apply the patch with reject and directory
git apply --reject -p3 --whitespace=fix --directory=package/server-ce/ ../tmp.diffe.g. copy across PR for develop to a new branch for the release branch
Step-by-step (assumes a clean new branch, no local changes):
- Fetch the PR diff from GitHub:
gh pr diff <PR_NUMBER> > /tmp/pr.diff - From the suite root, apply the diff project-wide:
git apply --reject -p1 --whitespace=fix /tmp/pr.diff - Resolve any
.rejfiles if they appear, then commit.
You can also use the script apply-pr-from-branch.sh (prompts for PR number and applies from the suite root).
git cherry-pick <hash>git format-patch sha1^..sha1
cd /path/to/2
git am -3 --reject --whitespace=fix /path/to/1/0001-...-....patchgit diff HEAD^ | git apply --reject -p3 --whitespace=fix --directory=package/server-ce/git branch -m old-branch-name new-branch-name
git push origin -u new-branch-name
git push origin --delete old-branch-namefor commit in $(git log --pretty='%H'); do
git diff -U0 --ignore-space-change "$commit^" "$commit" | grep '^-.*text that was deleted' > /dev/null && echo "$commit"
donegit checkout <branch_name> -- <paths>Remember to commit everything you've changed before you do this!
git rm -rf --cached .
git add .This removes all files from the repository and adds them back (this time respecting the rules in your .gitignore).
git branch -d <branch>git push <remote> --delete <branch>git commit -a --amend