|
2 | 2 |
|
3 | 3 | <details>
|
4 | 4 | <summary>
|
5 |
| -<em>How can I know if I’m in a bad situation?</em> |
| 5 | +<em>How to Hard Sync local Master with Original Upstream</em> |
6 | 6 | </summary>
|
7 | 7 |
|
8 |
| -- Run `gitk` or `gitk --all` to visualize the commit tree. |
9 |
| -- Check if `git log` shows any merge commits, indicating a lack of proper synchronization with the upstream branch. |
10 |
| -</details> |
11 |
| - |
12 |
| -<details> |
13 |
| -<summary> |
14 |
| -<em>How to Hard Sync Master with Upstream</em> |
15 |
| -</summary> |
16 |
| - |
17 |
| -To hard sync your local master branch with the upstream master branch, follow these steps in your main branch: |
18 |
| - |
19 |
| -- `git remote add upstream /url-to-original-repo` |
20 |
| -- `git fetch upstream` |
| 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` |
21 | 12 | - `git reset --hard upstream/main`
|
22 | 13 | - `git push origin main --force`
|
23 | 14 | </details>
|
24 | 15 |
|
25 |
| -## Better commits |
26 |
| - |
27 |
| -- Avoid committing unnecessary files: |
28 |
| - - Avoid using `git commit -a`, which commits everything. |
29 |
| -- Use targeted commit commands: |
30 |
| - - Use `git add` to stage specific files. |
31 |
| - - Use `git add -p` for a patch mode to review changes before staging. |
32 |
| -- Ensure changes are correct before committing: |
33 |
| - - Use `git diff --cached` to display staged changes. |
34 |
| - - Use `git commit -v` to view diffs while writing the commit message. |
35 |
| - |
36 |
| -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. |
37 |
| - |
38 | 16 | <details>
|
39 | 17 | <summary>
|
40 | 18 | <em>Edit a commit</em>
|
41 | 19 | </summary>
|
42 | 20 |
|
43 |
| -- `git reset --soft HEAD^`: Reset to the previous commit without changing files. |
44 |
| -- Edit the necessary changes. |
45 |
| -- `git commit -a -v -c ORIG_HEAD`: Recommit with the same message and verify changes. |
46 |
| -- After pushing, use force push: `git push -f`. |
47 |
| -</details> |
48 |
| - |
49 |
| -<details> |
50 |
| -<summary> |
51 |
| -<em>What should I do if I’m in a bad situation?</em> |
52 |
| -</summary> |
| 21 | +- `git reset --soft HEAD~1` gets back to the last commit(for more information refer this [blog](https://www.datacamp.com/tutorial/git-reset-revert-tutorial) ) |
| 22 | +- or |
| 23 | +- `git commit --amend`: ammend the most recent commit. |
| 24 | +- `git commit --amend -m "New commit message"` : you can set the commit message directly |
53 | 25 |
|
54 |
| -- **Rebase:** |
55 |
| - - Fetch the latest changes: `git fetch main` |
56 |
| - - Rebase onto the upstream branch: `git rebase upstream/main` |
57 |
| -- **Remove merge commits:** |
58 |
| - - Fetch latest changes: `git fetch upstream` |
59 |
| - - Discard all changes and reset: `git reset --hard upstream/main` |
60 |
| -- **Keep your changes:** |
61 |
| - - Create a backup branch: `git branch branchname` |
62 |
| - - Safely reset your branch |
63 |
| - - Pull changes back to master: `git cherry-pick branchname 1234567890abcdef1234567890abcdef12345678` |
64 | 26 | </details>
|
65 | 27 |
|
| 28 | + |
66 | 29 | <details>
|
67 | 30 | <summary>
|
68 |
| -<em>Recovering from a bad merge or accidental deletion</em> |
| 31 | +<em>To Check the commit Tree:</em> |
69 | 32 | </summary>
|
70 | 33 |
|
71 |
| -- `git reflog` |
72 |
| -- `git reset HEAD@{index}` |
| 34 | +- Run `gitk` or `gitk --all` to visualize the commit tree. |
| 35 | +- `git log` show commit logs. |
73 | 36 | </details>
|
74 | 37 |
|
75 | 38 | <details>
|
76 | 39 | <summary>
|
77 |
| -<em>Amending the last commit</em> |
| 40 | +<em>Undoing a commit from several commits ago</em> |
78 | 41 | </summary>
|
79 | 42 |
|
80 |
| -- `git commit --amend --no-edit` |
| 43 | +- `git log` |
| 44 | +- `git revert [hash of the commit]` |
81 | 45 | </details>
|
82 | 46 |
|
83 |
| -<details> |
84 |
| -<summary> |
85 |
| -<em>Changing the last commit message</em> |
86 |
| -</summary> |
87 | 47 |
|
88 |
| -- `git commit --amend` |
| 48 | +- **Rebase:** |
| 49 | + - `git fetch main`: Fetch the latest changes: |
| 50 | + - `git rebase upstream/main`: Rebase onto the upstream branch |
89 | 51 | </details>
|
90 | 52 |
|
91 |
| -<details> |
92 |
| -<summary> |
93 |
| -<em>Undoing a commit from several commits ago</em> |
94 |
| -</summary> |
95 | 53 |
|
96 |
| -- `git log` |
97 |
| -- `git revert [saved hash]` |
98 |
| -</details> |
| 54 | +- Avoid committing unnecessary files: |
| 55 | + - Avoid using `git commit -a`, which commits everything. |
| 56 | +- Use targeted commit commands: |
| 57 | + - Use `git add` to stage specific files. |
0 commit comments