thesuhu

Git Commands

Jan 29th, 2020 (edited)
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.86 KB | None | 0 0
  1. # clean up your local tracking branches for remote branches that have been deleted
  2. git fetch --prune
  3.  
  4. # If you want only the remote URL, or if your are not connected to a network that can reach the remote repo:
  5. git config --get remote.origin.url
  6.  
  7. # change the URI (URL) for a remote Git repository
  8. git remote set-url origin new.git.url/here
  9. # untuk cek
  10. git remote -v
  11.  
  12. # config user email
  13. git config --global user.name "John Doe"
  14. git config --global user.email johndoe@example.com
  15.  
  16. # You can view all of your settings and where they are coming from using:
  17. git config --list --show-origin
  18. git config --list
  19. git config user.name
  20.  
  21. # remove entry git config global
  22. git config --global --unset core.excludesfile
  23.  
  24. # edit langsung ke file config global
  25. git config --global --edit
  26.  
  27. # When using git clone (from GitHub, or any source repository for that matter) the default name for the source of the clone is "origin".
  28. # Using git remote show will display the information about this remote name.
  29. # If you require full output and you are on a network that can reach the remote repo where the origin resides :
  30. git remote show origin
  31.  
  32. # update working Git branch from another branch (develop)
  33. git checkout feature1
  34. git merge develop
  35.  
  36. # Cleaning Ignored Files
  37. git rm -r --cached .
  38. git add .
  39. git commit -m "Clean up ignored files"
  40.  
  41. # How to undo the last commit in git
  42. git reset HEAD^
  43. # If you want to revert a change that you have committed, do this:
  44. git revert <commit 1> <commit 2>
  45.  
  46. # unstage all files you might have staged with git add:
  47. git reset
  48.  
  49. # melihat diff setelah add (staged)
  50. # --cached means show the changes in the cache/index (i.e. staged changes) against the current HEAD.
  51. # --staged is a synonym for --cached.
  52. git diff --cached <nama file optional>
  53.  
  54. # revert all local uncommitted changes (should be executed in repo root):
  55. git checkout .
  56. # revert all local uncommitted changes (longer to type, but works from any subdirectory)
  57. git reset --hard HEAD
  58. # atau stash (lebih aman) undo all uncommitted or unsaved changes
  59. git add . (adding everything)
  60. git stash
  61. git stash drop
  62. # revert uncommitted changes only to particular file or directory:
  63. git checkout [some_dir|file.txt]
  64.  
  65. # remove all local untracked files, so only git tracked files remain:
  66. # WARNING: -x will also remove all ignored files, including ones specified by .gitignore!
  67. # You may want to use -n for preview of files to be deleted.
  68. git clean -fdx
  69. # note: use the -n option to see which files will be deleted. jika yakin gunakan -f
  70.  
  71. # force “git pull” to overwrite local files with remote files
  72. git checkout development
  73. git fetch --all
  74. git reset --hard origin/development
  75.  
  76. # executing commands below is basically equivalent to fresh git clone from original source
  77. # (but it does not re-download anything, so is much faster):
  78. git reset
  79. git checkout .
  80. git clean -fdx
  81.  
  82. # If you want to revert changes made to your working copy, do this:
  83. git checkout .
  84. # If you want to revert changes made to the index (i.e., that you have added), do this.
  85. # Warning this will reset all of your unpushed commits to master!:
  86. git reset
  87. # Or untracked directories (e.g., new or automatically generated directories):
  88. git clean -fd
  89.  
  90. # menambahkan tag
  91. git tag <tagname>
  92. # add with annotation
  93. git tag  -a <tagname> -m "some message"
  94. # push single tag
  95. git push origin <tag_name>
  96. # push bulk tag
  97. git push origin --tags
  98.  
  99. # melihat tampilan berapa log terakhir, misal 5
  100. git log -n <number-of-commits> --pretty=short
  101. # jika ingin tampil satu baris
  102. git log -n <number-of-commits> --pretty=oneline
  103. # melihat log perubahan file di commit mana aja, contoh:
  104. git whatchanged fuel/app/classes/controller/cpegawai.php
  105.  
  106. # melihat perubahan dalam commit
  107. git show 8d180725a79315fc1beba7f6caaf95372595bca9
  108. git show 8d180725a79315fc1beba7f6caaf95372595bca9 --name-only
  109. git show --color --pretty=format:%b 8d180725a79315fc1beba7f6caaf95372595bca9
  110.  
  111.  
  112. # melihat log siapa yang commit, kapan commit, file apa aja yg di-commit
  113. git log --stat -n 10 --name-only
  114.  
  115.  
  116.  
  117. # Use git log to view the commit history.
  118. # export diff antara 2 commit ke file txt
  119. git diff 3b1b3edfce62866b57b6f615b6e440b80025df97(sebelum)  33ef428468851e38ff1db232179ea9c20cf1aa6f(sesudah) > d:/temporary/diff.txt
  120. # melihat file apa aja yang berubah antara commit
  121. git diff --stat --diff-filter=ACRM --name-only f1f9ffa6439049d648dce5cc7538d06a1fbf1bb9 19eadcbaf35910c7b1345735e6bca4f6da11d5f8
  122.  
  123. # archive diff antara 2 commit ke file zip
  124. git archive --output=d:/temporary/diff.zip HEAD $(git diff --stat --diff-filter=ACRM --name-only f1f9ffa6439049d648dce5cc7538d06a1fbf1bb9 19eadcbaf35910c7b1345735e6bca4f6da11d5f8)
  125. # GET FILES BETWEEN TWO COMMIT WHICH WAS CHANGED OR NEW CREATE
  126. git archive --format=zip --output=d:/temporary/files.zip HEAD $(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD)
  127. git archive --output=d:/temporary/files.tar HEAD $(git diff-tree -r --no-commit-id --name-only --diff-filter=ACMRT HEAD)
  128.  
  129. # If you want to get an overview over all the differences that happened from commit to commit,
  130. # use git log or git whatchanged with the patch option:
  131. # include patch displays in the commit history (termasuk menampilkan baris perubahannya)
  132. git log -p
  133. git whatchanged -p
  134. # contoh lihat hanya 1 file
  135. git log -p fuel/app/classes/controller/cpegawai.php
  136. # only get history of those commits that touch specified paths (hanya menampilkan berubah dicommit apa aja)
  137. git log path/a path/b
  138. git whatchanged path/c path/d
  139.  
  140. # How to remove git files, directories in .gitignore from a remote repository
  141. # Step 1: Unstage the files/directory
  142. git rm -r --cached src/environments/environment.ts
  143. git rm -r --cached src/environments/environment.prod.ts
  144. # Step 2: Make new commit
  145. git commit -am "Remove ignored file"
  146. # Step 3: Push changes to remote git repository
  147. git push origin bugfix
  148.  
  149. # alias
  150. git config --global alias.co checkout
Add Comment
Please, Sign In to add comment