git reset --soft HEAD~1 # this undoes the last commit and preserves last changes
git pull
git commit -m 'my erased last commit comments'
git push
Act as an agent that generates raw markdown pull request descriptions following the structure below.
Compare the current branch with a reference branch, analyze all differences, and generate a clear, professional, and technical summary.
The output must be in raw markdown, enclosed in triple backticks (```), ready to copy and paste.
### Required structure:
1. **Overview**
- High-level summary of the purpose of this PR.
- Explain the feature, fix, or improvement in 2–3 sentences.
2. **Changes**
- Group file changes into categories:
- ✨ **Added**: new files or major additions.
- 🔧 **Modified**: updated or refactored files.
- 🗑️ **Removed**: deleted files.
- Under each category, list the files changed and add short inline explanations if needed.
3. **How it works**
- Step-by-step explanation of the core logic or workflow introduced by this PR.
- Include how components interact and important flows.
4. **Deployment Notes**
- Mention configuration changes, env vars, migrations, or background jobs needed.
5. **Impact**
- Explain how this change affects the system, workflows, or end-users.
### Constraints:
- The tone must be professional and suitable for a technical audience.
- Summarize code differences accurately.
- Do not render markdown formatting; output raw markdown within triple backticks.
Now, analyze the diff between the current branch and reference branch {{reference_branch}}, and generate the PR description.
Scenario: You have pushed several commits to the staging environment and now want to squash them all into a single commit. Once you are satisfied with your branch and QA:
git log and copy the hash of the commit just before your first partial commit.
git rebase -i <the-hash>.
In the interactive rebase editor, replace pick with r for the top commit and s for the rest. Follow the instructions, removing any unnecessary information. Once finished, push your changes with
git push --force-with-lease
git fetch origin <parent>
git merge origin/<parent>
git checkout <parent-branch-name> <conflicted-file-path>
rails db:rollback #until it is matched with master
git checkout --theirs db/schema.rb
rails db:migrate
git add .... etc
git log path/to/file
# get the version of the file from the given commit
git checkout <commit> path/to/file
git commit
git checkout -p <source-branch> -- <path-to-file-or-folder>
git checkout -p develop -- .circleci
edit .gitignore file to add the line
.env
git rm -r --cached .env
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch .env" HEAD
git push --force
git diff HEAD~10 HEAD --stat lib/tasks/seed
git branch --show-current
git stash
git stash pop
git stash show -p stash@{1}
git clone -b <branchname> <remote-repo-url>
i.e.
git clone -b the-branch-name [email protected]:FakeCompany/reponame.git
git stash
git checkout targetbranch
git stash apply
git log
=> Copy the last good commit hash
git reset <CopiedHasH>
git status
git checkout <files>
=> start over
git log
=> Copy the desired target commit hash
git checkout <CopiedHasH>
=> do wherever you want
git reflog # to see HEAD movements and copy <hash_to_return>
git reset --hard <hash_to_return>
git branch -r
git checkout -b <new-local-branch> <remote-branch-to-clone>
git branch -m old_branch_name new_branch_name
git push origin :old-name new-name
git checkout .
git log
=> Copy the last good commit hash
git reset --hard <CopiedHasH>
git pull
.. or just
git reset --hard HEAD~n
git reset --hard # will reset tracked changes
git clean -fd # will delete untracked files and folders
git commit -am "My comment"
git commit --amend -m "new corrected message"
git commit --amend --no-edit
git rebase -i <commit>^ #look at ^ symbol
=> set edit, drop or whatever in vim then save&exit :wq
=> do changes in files if any
git add <files>
git commit --amend
git rebase --continue
git push --force
=> standing in <old-pushed-branch> with <wrong-base-branch> as base
git log
> copy the commit/s hash/es with your changes - clipboard <old-branch-commit-hash>
git checkout <right-branch>
git pull
git checkout -b <new-from-right-branch>
git cherry-pick <old-branch-commit-hash>
git push -f origin <new-from-right-branch>:<old-pushed-branch>
git reset HEAD <file_path> ## restore to working keeping changes
git reset -- my-file.txt ## unstage this file
git checkout HEAD -- my-file.txt
git checkout @ -- myfile.ext
git checkout [commit ID] -- path/to/file
git checkout <source-branch> path/filename
git diff --numstat [remote repo/branch]
# New files in a branch
git diff --name-status master..feature-branch-name | grep ^A
# Specific file or folder
git diff <reference-branch> <path/file.name>
# Specific *remotes* file or folder
git diff <remote-reference-branch> <remote-modified-branch> <path/file.name>
git diff origin/master origin/development app/lib/whatever/filename.rb
# Differences in GITHUB
# add `/compare` at the end of repository url
git commit --allow-empty -am 'empty commit to force hooks'
git config core.sshCommand "ssh -o IdentitiesOnly=yes -i ~/.ssh/private-key-filename-for-this-repository -F /dev/null"
git commit --author='Pepe Mujica <[email protected]>'
git rm -r --cached .
git add .
git commit -m "untrack files contained in the .gitignore file"
git commit --date='10 day ago' -m 'comment'
git commit --date='2020-03-20' -m 'comment'
git reset --merge HEAD~1
multiple commits
git cherry-pick hashA^..hashB //(hashA commit included)
git cherry-pick hashA..hashB //(hashA commit excluded)