Skip to content

Commit 54abb70

Browse files
feat-krishnaacharyaa#378: created readme for git conflicts
1 parent a8434d3 commit 54abb70

File tree

1 file changed

+75
-52
lines changed

1 file changed

+75
-52
lines changed

Diff for: GIT_CONFLICTS.md

+75-52
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,100 @@
1-
# Wanderlust Project
2-
3-
## Overview
4-
Welcome to the Wanderlust project! This is a collaborative effort to build an amazing application. We appreciate your contributions and aim to make the process as smooth as possible.
1+
## Welcome to the Wanderlust project! This is a collaborative effort to build an amazing application. We appreciate your contributions and aim to make the process as smooth as possible.
52

63
## Common QnA for Git and Open Source Contributions
74

85
<details>
96
<summary>
10-
11-
### How can I know if I’m in a bad situation?
7+
<em>How can I know if I’m in a bad situation?</em>
128
</summary>
13-
I suggest you to run **`gitk`** or **`gitk --all`**. The commit tree should be self-explainatory.
149

15-
Also, if **`git log`** shows you any merge commits, this means that it isn’t properly synced with the upstream branch
10+
- Run `gitk` or `gitk --all` to visualize the commit tree.
11+
- Check if `git log` shows any merge commits, indicating a lack of proper synchronization with the upstream branch.
1612
</details>
1713

18-
### How to Hard Sync Master with Upstream
14+
<details>
15+
<summary>
16+
<em>How to Hard Sync Master with Upstream</em>
17+
</summary>
18+
1919
To hard sync your local master branch with the upstream master branch, follow these steps in your main branch:
20-
```
21-
git remote add upstream /url-to-original-repo
22-
git fetch upstream
23-
git reset --hard upstream/main
24-
git push origin main --force
25-
```
20+
21+
- `git remote add upstream /url-to-original-repo`
22+
- `git fetch upstream`
23+
- `git reset --hard upstream/main`
24+
- `git push origin main --force`
25+
</details>
26+
2627
## Better commits
2728

28-
You should not push what is not needed. Doing **`git commit -a`**, instead, commits just everything. This, often, is bad.
29-
You’d better use **`git add`** and, most of all, **`git add -p`**
30-
**`-p`** stays for “patch”: it will ask, for each “block” of code which you could commit, if you really want to commit it.
31-
It is very simple to use, and will make you more responsible about what you’re commiting.
29+
- Avoid committing unnecessary files:
30+
- Avoid using `git commit -a`, which commits everything.
31+
- Use targeted commit commands:
32+
- Use `git add` to stage specific files.
33+
- Use `git add -p` for a patch mode to review changes before staging.
34+
- Ensure changes are correct before committing:
35+
- Use `git diff --cached` to display staged changes.
36+
- Use `git commit -v` to view diffs while writing the commit message.
3237

33-
If you want to make sure about what you’re commiting, use **`git diff --cached`**, it will display the ready-to-commit changes.
34-
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.
38+
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.
3539

36-
## Edit a commit
37-
Sometimes you committed something, but someone asks you to fix something, or you want to fix something yourself. Instead of making a new commit, you can also edit the previous commit(s).
40+
<details>
41+
<summary>
42+
<em>Edit a commit</em>
43+
</summary>
3844

39-
**`git reset --soft HEAD^`** (will reset the commit history to the previous commit. The —soft option makes sure the files don’t get reset too)
40-
Then edit whatever you want to edit
41-
**`git commit -a -v -c ORIG_HEAD`** (recommits with the same commit message. Because of the -v option, you can check if everything goes well)
45+
- `git reset --soft HEAD^`: Reset to the previous commit without changing files.
46+
- Edit the necessary changes.
47+
- `git commit -a -v -c ORIG_HEAD`: Recommit with the same message and verify changes.
48+
- After pushing, use force push: `git push -f`.
49+
</details>
4250

43-
If you do this after pushing, you’ll have to use **`git push -f`** next time you try to push.
51+
<details>
52+
<summary>
53+
<em>What should I do if I’m in a bad situation?</em>
54+
</summary>
4455

45-
## What should I do if I’m in a bad situation?
56+
- **Rebase:**
57+
- Fetch the latest changes: `git fetch main`
58+
- Rebase onto the upstream branch: `git rebase upstream/main`
59+
- **Remove merge commits:**
60+
- Fetch latest changes: `git fetch upstream`
61+
- Discard all changes and reset: `git reset --hard upstream/main`
62+
- **Keep your changes:**
63+
- Create a backup branch: `git branch branchname`
64+
- Safely reset your branch
65+
- Pull changes back to master: `git cherry-pick branchname 1234567890abcdef1234567890abcdef12345678`
66+
</details>
4667

47-
[](https://github.com/emesene/emesene/wiki/GitHowTo#what-should-i-do-if-im-in-a-bad-situation)
68+
<details>
69+
<summary>
70+
<em>Recovering from a bad merge or accidental deletion</em>
71+
</summary>
4872

49-
rebase.
50-
Just do **`git fetch main`** (fetch the latest changes from the upstream branch)
51-
**`git rebase upstream/main`** (rebase upon the upstream branch)
73+
- `git reflog`
74+
- `git reset HEAD@{index}`
75+
</details>
5276

53-
Sometimes, if you have any merge commits in your branch, this won’t work. The best way to get rid of them is using **`git fetch upstream`** (this will fetch the latest changes of the upstream branch) and then do **`git reset --hard upstream/main`**. BE AWARE THAT THIS WILL THROW AWAY ALL YOUR CHANGES.
77+
<details>
78+
<summary>
79+
<em>Amending the last commit</em>
80+
</summary>
5481

55-
If you want to keep your changes, you can put them in a different branch first **`git branch branchname`**. Now you’ll have a branch with your committed changes backed up. It’s now safe to reset. If you want to pull the changes back to your master branch, you could use **`git cherry-pick branchname 1234567890abcdef1234567890abcdef12345678`**, where 1234567890abcdef1234567890abcdef12345678 is the commit you want in your master branch.
82+
- `git commit --amend --no-edit`
83+
</details>
5684

85+
<details>
86+
<summary>
87+
<em>Changing the last commit message</em>
88+
</summary>
5789

58-
### Recovering from a bad merge or accidental deletion
59-
```
60-
git reflog
61-
git reset HEAD@{index}
62-
```
63-
### Amending the last commit
64-
```
65-
git commit --amend --no-edit
66-
```
90+
- `git commit --amend`
91+
</details>
6792

68-
### Changing the last commit message
69-
```
70-
git commit --amend
71-
```
93+
<details>
94+
<summary>
95+
<em>Undoing a commit from several commits ago</em>
96+
</summary>
7297

73-
### Undoing a commit from several commits ago
74-
```
75-
git log
76-
git revert [saved hash]
77-
```
98+
- `git log`
99+
- `git revert [saved hash]`
100+
</details>

0 commit comments

Comments
 (0)