Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat-#378: created readme for git conflicts #412

Closed
98 changes: 98 additions & 0 deletions GIT_CONFLICTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
## Common QnA

<details>
<summary>
<em>How can I know if I’m in a bad situation?</em>
</summary>
krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved

- Run `gitk` or `gitk --all` to visualize the commit tree.
- Check if `git log` shows any merge commits, indicating a lack of proper synchronization with the upstream branch.
</details>

krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved
<details>
<summary>
<em>How to Hard Sync Master with Upstream</em>
</summary>
krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved

krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved
To hard sync your local master branch with the upstream master branch, follow these steps in your main branch:

- `git remote add upstream /url-to-original-repo`
- `git fetch upstream`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can say it directly taken from the AI and not tested, how can /url-to-original-rep work?
Acceptance criteria was everthing should be tested and working, and for now only 2 points we need to have as previous review comment

- `git reset --hard upstream/main`
- `git push origin main --force`
</details>

## Better commits

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this?

- Avoid committing unnecessary files:
- Avoid using `git commit -a`, which commits everything.
- Use targeted commit commands:
- Use `git add` to stage specific files.
- Use `git add -p` for a patch mode to review changes before staging.
- Ensure changes are correct before committing:
- Use `git diff --cached` to display staged changes.
- Use `git commit -v` to view diffs while writing the commit message.

If you want to make sure about what you’re committing, use `git diff --cached` to display the ready-to-commit changes. Also, I like to use `git commit -v`, which displays the diff as a comment, so that I can view it while writing the commit message.

<details>
<summary>
<em>Edit a commit</em>
</summary>

- `git reset --soft HEAD^`: Reset to the previous commit without changing files.
- Edit the necessary changes.
- `git commit -a -v -c ORIG_HEAD`: Recommit with the same message and verify changes.
- After pushing, use force push: `git push -f`.
</details>

<details>
<summary>
<em>What should I do if I’m in a bad situation?</em>
</summary>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment, kindly consider the review comment as whole, and don't expect me to hand hold and to pin point everything, I am not rigid on the content, but i accept the review comments are gracefully accepted and worked on


- **Rebase:**
- Fetch the latest changes: `git fetch main`
- Rebase onto the upstream branch: `git rebase upstream/main`
- **Remove merge commits:**
- Fetch latest changes: `git fetch upstream`
- Discard all changes and reset: `git reset --hard upstream/main`
- **Keep your changes:**
- Create a backup branch: `git branch branchname`
- Safely reset your branch
- Pull changes back to master: `git cherry-pick branchname 1234567890abcdef1234567890abcdef12345678`
</details>

krishnaacharyaa marked this conversation as resolved.
Show resolved Hide resolved
<details>
<summary>
<em>Recovering from a bad merge or accidental deletion</em>
</summary>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is actually required, this section


- `git reflog`
- `git reset HEAD@{index}`
</details>

<details>
<summary>
<em>Amending the last commit</em>
</summary>

- `git commit --amend --no-edit`
</details>

<details>
<summary>
<em>Changing the last commit message</em>
</summary>

- `git commit --amend`
</details>

<details>
<summary>
<em>Undoing a commit from several commits ago</em>
</summary>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Included already in the readme and this is FnQ, not a good place for good practice,
Only most popular trick GitHub questions and neatly providing suggestions to solve that


- `git log`
- `git revert [saved hash]`
</details>