-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitCommands.txt
93 lines (71 loc) · 4.06 KB
/
gitCommands.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
Basic setUp:
git config --global user.name "John Doe"
git config --global user.email "[email protected]
git config --list : To show all the credential-details
git --version
Basic Commands:
ls // To show all files in working directory
ls -a // TO show all file & directory
ls -R // To show all files & directory in details .
git ls-files // To show all files in Staging area
git log // To show all commit in git local repo.
git init // To inialise empty git repo
touch filename // To make a new filename file
git status // Will show the status like tracked file or untracked file any changes
git log // Show all commit history
git log branchName // Show all commit history of the branchName
git log -n 5 // Show last 5 commit
git log --oneline // Show the commit history with id & branch only
git log --oneline --graph // Show the commit history with id & branch in graph form
echo Content > filename // To write Overwrite Content in filename it will erase previous Content if any
ehco Content >> filename // To append Content
Commits & Basic Staging:
git add filename // To add filename in Staging area
git add -A // To add all filename in Staging area
git diff // Show diff b/w all files
git diff arg1 arg2 // Show diff b/w arguement
git diff --staged filename // Diff b/w staged filename & working directory filename
git restore --staged filename // To unstage the change
git commit -m "message" // To commit with specified message
git commit -a -m "message" // To commit with specified message which is already in Staging area
Restoring files:
git restore --staged file // To restore the deleted file in Staging area
Removing files:
rm file // To remove file from working directory
git rm file // To remove file from Staging area & working directory
git rm -r . // To remove all files
git rm --cached filename // To remove filename from Staging
git rm -f file // To delete file from Staging & working directory
Basic Branching:
git branch // To show all branches
git branch branchName // To make new branch with branchName
git switch branchName or git checkout branchName // To switch to the branchName
git diff <branchA> <branchB> // To diff b/w branchA & branchB
git checkout -b branchName // Making new branch & switch to it
Merging:
git merge branchName // To merge branchName with present branch where you are in
git merge <branchA> <branchB> // To merge with branchA & branchB
Rebasing:
git rebase main // To rebase the main with the feature branch
git merge feature // Merging the feature in the main
diff :
destination source
(working directory -> Staging area -> Git local repo -> Remote )
git diff file // diff of file content b/w working directory & Staging area
git diff HEAD file // diff of file content b/w working directory & git local repo
git diff --staged HEAD file // diff of file content b/w Staging area & last commit(Git local repo) of the file
git diff commitId file // diff of file content b/w specific commit & working directory .
git diff --staged id // diff of file content b/w specific commit & Staging area
git diff commitId1 commitId2 // Diff of content b/w commitId1 & commitId2
git diff branchA branchB // Diff of content b/w branchA & branchB
Reverting :
git revert <commitId> // To revert the specified commitId
git revert // on the newest commit, to remove the changes the last commit added
git revert -e commitId // To edit commit msg before reverting the commit
git checkout -- filename // To undo the Content of working directory as Staging area Content of the filename
Reset (Mode: --mixed --soft --hard ) :
git reset filename // Remove file from Staging area it won't affect the working directory
git reset --mixed commitId // To discard/undo/restore changes from git local repo(commit history) & Staging area for that commitId
git reset --soft commitId //To discard/undo/restore changes from git local repo only. It will not affect the Staging area & working directory .
git reset --hard commitId // To discard/undo/restore changes from everywhere. No way to revert
git reset mode HEAD~1 // It will move head one step back . To discard last commit