DEV Community

adegiamb
adegiamb

Posted on

1 1 1 3 1

A Merge Strategy using reset --soft

While working on a feature or code change, we may need to commit debugging statements or PR comments to the branch where the changes are made.

However, once all the changes are completed and approved, we want to clean up the commit history to help keep the destination branch neat and with helpful commit messages.

While working with a coworker, they cleaned up their comments before merging them into the final branch using the git reset—-soft strategy.

Steps

  1. First, make sure the <destintion branch> is up to date git pull origin

  2. Confirm the source branch is checkout out (git checkout <branch name>). If the branch was checked out locally, ensure all changes are synced by git call.

  3. Next we are going reset the ref pointer to <destintion branch> by running git reset --soft <destintion branch>.

  4. Running git status will show what has changed.
    Note: This is optional.

  5. Depending on what makes a scene, we can now commit our changes in the logical group(s) or one commit.

Please review the git commit command to see the different options.

  1. Once all the changes are committed, we will not push them back to the origin branch git push origin <branch name> --force-with-lease

That is all that is needed, and now we have a clean and neat commit(s).

Example

working branch -> feat/adg-01-sample
destination branch -> master

git pull origin master
git checkout feat/adg-01-sample
git reset --soft master
git commit -am "ADG-O2 Sample reset"
git push origin feat/adg-01-sample --force-with-lease
Enter fullscreen mode Exit fullscreen mode

reset --soft master -> A soft reset in Git allows you to undo changes to your commit history while keeping the working directory intact

-force-with-lease -> is a safer option that will not overwrite any work on the remote branch if a team member adds more commits. It ensures you do not overwrite someone else's work by force-pushing.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (1)

Collapse
 
bdestrempes profile image
Benjamin Destrempes

Great write-up! I've been using this git reset --soft flow for ages, and it's seriously so handy for larger diffs. This, combined with staging/committing in ranges instead of whole files, really helps keep commits atomic and meaningful. 👍

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more