-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit_command
104 lines (80 loc) · 2.92 KB
/
git_command
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
93
94
95
96
97
98
99
100
101
102
103
Git Command.
- git remote add origin `<url>`
- git add .
- git commit -a -m 'messsage'
- git push origin master
undo pull:
----------
- git reset --hard HEAD@{1}
Last commit Revert:
----------------------
1. With Staged files:
- git reset --soft HEAD~1
2. With Un-Staged files:
- git reset --hard HEAD~1
Git Rebase:-
------------
- git rebase branch (from which do you want)
- git rebase --continue (to continue rebasing if there is already opened any directory)
- git rebase --abort (to abort it)
- git rebase --skip (to skip it)
set git upstream with origin
------------------------------
- git remote add upstream https://gitlab.isdatatower.com/user-interface/vi.git
- git fetch upstream
- git rebase upstream/master
- git push origin master --force
---------------
Stash Related:-
---------------
- git stash -u (to stash all)
- git stash list
- git stash apply stash@{number which you want to apply}
PULL
1) undo last pull
git reset --hard HEAD@{1}
PUSH
1) revert last commit
git reset HEAD~
2) With Staged files:
git reset --soft HEAD~1
How do you recover a deleted branch that was not merged
--git reflog
--git checkout -b preprod HEAD@{4}
Delete the branch
-git branch -D preprod
-git push origin --delete quickfix
Change author name into commit
1) If already available this backup refs/original/ folder as backup in git repo, remove this backup folder using. Otherwise it will block you to change the commit author name and email id:
2)If you want to change author name for specific one commit, you can follow this command
rm -rf .git/refs/original/
-> git filter-branch --env-filter '
if [ "$GIT_COMMIT" = "COMMIT_ID" ]; then
export GIT_AUTHOR_NAME="NewName";
export GIT_AUTHOR_EMAIL="newemail@example.com";
export GIT_COMMITTER_NAME="NewName";
export GIT_COMMITTER_EMAIL="newemail@example.com";
fi
' --tag-name-filter cat -- --branches --tags
-> git push origin --force --all
3)If you want to change author name for Multiple commit, you can follow this command
-> git filter-branch --env-filter '
if [ "$GIT_COMMIT" = "COMMIT_ID1" ]; then
export GIT_AUTHOR_NAME="NewName1";
export GIT_AUTHOR_EMAIL="newemail1@example.com";
export GIT_COMMITTER_NAME="NewName1";
export GIT_COMMITTER_EMAIL="newemail1@example.com";
fi
if [ "$GIT_COMMIT" = "COMMIT_ID2" ]; then
export GIT_AUTHOR_NAME="NewName2";
export GIT_AUTHOR_EMAIL="newemail2@example.com";
export GIT_COMMITTER_NAME="NewName2";
export GIT_COMMITTER_EMAIL="newemail2@example.com";
fi
# Add more conditions for additional commits if needed // remove this line while hitting this command
' --tag-name-filter cat -- --branches --tags
-> git push origin --force --all
In the last commit ID will be change for every commit which you have changed the author name and email id.
remove code upto given commit id
- git reset --hard <commit_id>
- git push --force