Skip to content

Commit

Permalink
docs: Added note for git reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Varun-Kolanu committed May 28, 2024
1 parent 64ead50 commit a008630
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

---

# Contributing to Multiplayer UNO Game
Expand Down Expand Up @@ -91,7 +90,7 @@ If any merge conflicts occur, you will need to resolve them manually. Code edito
Now the local copy of the branch is synced with upstream/main. You need to force push these changes to origin, since the commit history has been rewritten.

```bash
git push origin <branch-name> --force
git push --force
```

### Editing commit history
Expand Down Expand Up @@ -129,13 +128,17 @@ pick 3m4n5o6p Commit msg 4
```
Save the changes and exit.

After saving the changes, git will then apply the 2nd commit and pause. You can now make the necessary changes to the code, and then stage the changes (Using `git add .`). You then incorporate the changes to the 2nd commit using `git commit --amend`. You can also change the commit message using this command.
After saving the changes, git will then apply the 2nd commit and pause. You can now make the necessary changes to the code, and then stage the changes (Using `git add .`). You then incorporate the changes to the 2nd commit using `git commit --amend`. The editor opens, asking for commit meessage. You can change the commit message if needed at this needed.


#### "Uncommitting" a commit
When you choose to edit the 2nd commit, git pauses **after** applying the second commit. You might wish to uncommit all the changes made in the 2nd commit. In that case, you run `git reset HEAD~1`. This will uncommit the changes made in the 2nd commit, but keep the changes in the working directory. You can then make the necessary changes and commit them again. The `git reset` command can be used to uncommit any number of commits. For example, `git reset HEAD~2` will uncommit the last 2 commits. Note that after doing this operation, there would be no way to distinguish the changes made in the two commits. This command can be used outside of an interactive rebase as well.

After making the changes, you can continue the rebase process by running `git rebase --continue`. Git will then apply the 3rd commit and pause again. You can then change the commit message using `git commit --amend`. After making the changes, you can continue the rebase process by running `git rebase --continue`.

When there are no more commits left, the rebase process will be complete.

After all the commits have been applied, you can push the changes to your branch using `git push origin <branch-name> --force`. This will overwrite the commits in the remote branch in your forked repository with the changes you just made locally.
After all the commits have been applied, you can push the changes to your branch using `git push --force`. This will overwrite the commits in the remote branch in your forked repository with the changes you just made locally.

#### Tip
VSCode provides a helpful UI to perform these operations. You can set the default text editor for Git to VSCode by running the following command:
Expand Down

0 comments on commit a008630

Please sign in to comment.