Skip to content

Commit 2caf2b1

Browse files
author
maverickjoy
committed
Updating
1 parent 8274ed8 commit 2caf2b1

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed

README.md

+134
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,127 @@
1313
1414
----------
1515

16+
**Advanced**
17+
18+
- To Revert/Recall Changes:
19+
- IF LOCAL CHANGES, NO COMMIT MADE.
20+
- These can be in two stages:
21+
- Staged / Unstaged : Difference between them is have you added them or not.
22+
If added using `git add` command, then staged, otherwise unstaged.
23+
- Now for any local changes in staged section, ideally should be brought to unstaged section
24+
before removing it.
25+
- Command
26+
```
27+
# particular files
28+
git reset HEAD <file1> <file2>
29+
30+
# all files
31+
git reset HEAD
32+
```
33+
- Once local changes in unstaged section, you can remove these changes:
34+
- Command
35+
```
36+
git restore <file1> <file2>
37+
# or
38+
git checkout <file1> <file2>
39+
```
40+
- IF COMMIT MADE, BUT NOT PUBLISHED
41+
- If you want to keep the changes just want to do some edit.
42+
- Command
43+
```
44+
# from hash, if you want to go back to a particular commit use its hash
45+
git reset --soft 0bfabb11a8ce2b61dbf204ee3bc55ba58df354fd
46+
47+
# from count from top, replace 2 with count of top commits you want to remove
48+
git reset --soft HEAD~2
49+
```
50+
- If you dont want to keep the changes just clean.
51+
- Command
52+
```
53+
# from hash, if you want to go back to a particular commit use its hash
54+
git reset --hard 0bfabb11a8ce2b61dbf204ee3bc55ba58df354fd
55+
56+
# from count from top, replace 2 with count of top commits you want to remove
57+
git reset --hard HEAD~2
58+
```
59+
60+
- IF COMMIT MADE, AND PUBLISHED
61+
- If there are more people working on it use revert. Which will create a rollback commit aswell.
62+
- When we do revert changes of those commits removed and get staged for the commit to imply removing these changes.
63+
- Command
64+
```
65+
# From particular hash to head rollback, to that particular hash comit all above commits will be removed.
66+
git revert --no-commit 0bfabb11a8ce2b61dbf204ee3bc55ba58df354fd..HEAD
67+
68+
# If you want to revert by count from top, replace 3 by count number
69+
git revert --no-commit HEAD~3..HEAD
70+
```
71+
72+
- If anything unwanted happened and too much of confusion with commits or reverts or anything:
73+
- Simple stash the unsaved changes and do `git pull`
74+
- It will bring your local syste to repository git status.
75+
- To pull changes after commit, therefore always do, `git pull --rebase`, it will bring your commit on top
76+
of other commits and then do `git push origin`
77+
78+
79+
- Stash: We use stash for saving our local changes so that we can pull or work on different commmits
80+
- Command
81+
```
82+
# To Stash
83+
git stash
84+
85+
# To view a particular stash
86+
git stash show -p stash@{1}
87+
88+
# To apply a particular stash
89+
git stash apply stash@{1}
90+
91+
# To apply top Stash
92+
git stash apply
93+
94+
# To apply and remove top Stash
95+
git stash pop
96+
97+
# To drop a particular Stash
98+
git stash drop stash@{1}
99+
100+
# To see stash list
101+
git stash list
102+
103+
# To clear stash list
104+
git stash clear
105+
```
106+
107+
- Check git logs:
108+
- Command
109+
```
110+
# Git check all logs, use q to exit, if logs are more than screen size and down button to explore all
111+
git logs
112+
113+
# to view top x logs, replace 5 with x number in the below commands.
114+
git logs -n 5
115+
116+
# To check log graph and its branches in detailed manner
117+
git log --graph --oneline --decorate --all
118+
```
119+
120+
- To cherry pick a commit:
121+
- Command
122+
```
123+
# Go to branch from where you want to pick
124+
git checkout branch_name
125+
126+
# View its commits
127+
git log
128+
129+
# Go to original branch
130+
git checkout original_branch
131+
132+
# cherry pick commit
133+
git cherry-pick commit_id
134+
```
135+
136+
----------
16137
**Pull**
17138
18139
- To pull a branch
@@ -42,6 +163,12 @@ Remote's are generally places where git repositories of your interest are situat
42163
- Check all remote names already present
43164
> **git remote**
44165
166+
If remote not added, then add remote first.
167+
> **git fetch <remote_name>**
168+
169+
To get all branches
170+
> **git fetch --all**
171+
45172
- To add a new remote
46173
> **git remote add <remote_name> <remote_url>**
47174
@@ -58,6 +185,9 @@ Remote's are generally places where git repositories of your interest are situat
58185
- Check all branch names already present
59186
> **git branch**
60187
188+
To get all branches
189+
> **git fetch --all**
190+
61191
- Create a branch
62192
> **git checkout -b <branch_name>**
63193
@@ -116,3 +246,7 @@ First we will add a remote(forked_repo_clone_url) and name it as `upstream`.
116246
117247
- Check present git information
118248
> **git status**
249+
250+
- To view a commit changes
251+
> **git show commit_hash**
252+
----------

0 commit comments

Comments
 (0)