Skip to content

Commit 518a405

Browse files
feat-krishnaacharyaa#378: created readme for git conflicts
1 parent 954593b commit 518a405

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

Diff for: GIT_CONFLICTS.md

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
## Common QnA
2+
3+
<details>
4+
<summary>
5+
<em>How to Hard Sync local Master with Original Upstream</em>
6+
</summary>
7+
8+
Follow these steps in your main branch
9+
(upstream" is the original repository and "origin" is the fork one) :
10+
- `git checkout main`
11+
- `git pull upstream main`
12+
- `git reset --hard upstream/main`
13+
- `git push origin main --force`
14+
</details>
15+
16+
<details>
17+
<summary>
18+
<em>Why the previous commits of another branch are showing in the new branch</em>
19+
</summary>
20+
21+
When you create a new branch from a particular branch, you'll start from the point where that branch currently is. So all commit history will be there in the new branch as well.
22+
23+
![image showing the working of branches](https://github.com/rushil-b-patel/wanderlust/assets/96254453/1689fdd3-8ee5-4c29-9b69-f2eeed67f96e)
24+
25+
A good rule of thumb is to always create a new branch from the branch that you intend to eventually merge the new branch into (main branch). So if D is intended to be merged into main at some future point in time, create it from the current tip of main.
26+
27+
for more details refer this [blog](https://www.reddit.com/r/git/comments/l7epj0/why_does_my_new_branch_contain_commits_from/)
28+
</details>
29+
30+
<details>
31+
<summary>
32+
<em>Edit a commit</em>
33+
</summary>
34+
35+
1. `git add `: Add new changes
36+
2. `git commit --amend --no-edit`: it will combine the new staged files to the last commit.
37+
38+
**or**
39+
40+
When calling git reset, you need to specify the commit to reset to or you can specify an ancestor of HEAD, the current commit, using the tilde (~) suffix.
41+
- `git add .`
42+
- `git commit -m "This commit is a mistake"`
43+
- `git reset HEAD~`
44+
- `git add main.py # need to re-add files after reset`
45+
- `git commit -m "This commit corrects the mistake"`
46+
47+
To undo the last two commits, use the commands:
48+
- `git add .`
49+
- `git commit -m "This commit is a mistake"`
50+
- `// make changes`
51+
- `git add .`
52+
- `git commit -m "This commit is another mistake"`
53+
- `git reset HEAD~2`
54+
- `git add .`
55+
- `git commit -m "this commit corrects both mistakes"`
56+
57+
for more info refer this [blog](https://sentry.io/answers/undo-the-most-recent-local-git-commits/)
58+
59+
**or**
60+
61+
- `git commit --amend -m "New commit message"`: it will chnage the last commit message
62+
![git ammend showcase](https://github.com/rushil-b-patel/wanderlust/assets/96254453/4c5e73b1-e466-42b4-9053-d7044be4a50e)
63+
for more info, watch this [video](https://www.youtube.com/watch?v=q53umU5vMkk)
64+
</details>
65+
66+
67+
<details>
68+
<summary>
69+
<em>To Check the commit Tree:</em>
70+
</summary>
71+
72+
- Run `gitk` or `gitk --all` to visualize the commit tree.
73+
- `git log` show commit logs.
74+
</details>
75+
76+
- **Rebase:**
77+
- `git fetch main`: Fetch the latest changes:
78+
- `git rebase upstream/main`: Rebase onto the upstream branch
79+
</details>
80+
81+
82+
- Avoid committing unnecessary files:
83+
- Avoid using `git commit -a`, which commits everything.
84+
- Use targeted commit commands:
85+
- Use `git add` to stage specific files.

0 commit comments

Comments
 (0)