阿川私房教材:學程式,拿 offer!

63 個專案實戰,直接上手!
無需補習,按步驟打造你的面試作品。

立即解鎖你的轉職秘笈

介紹

Git 是軟體工程師的必備工具,可實現高效的版本控制、協作和專案管理。無論您是從事獨立專案還是大型團隊的一部分,掌握 Git 命令對於簡化開發工作流程都至關重要。本指南涵蓋了您需要的最常見的 Git 命令,為管理程式碼庫、追蹤變更以及與其他開發人員協調提供了堅實的基礎。透過熟悉這些命令,您可以提高工作效率並確保專案順利進行。讓我們深入了解每個軟體工程師都應該知道的關鍵 Git 命令。

配置

1.git配置

Purpose: Configure Git settings, such as user name and email.


範例: git config --global user.name "你的名字"

2. 加熱

Purpose: Initialize a new Git repository.


範例:git 初始化

3. git克隆

Purpose: Clone an existing repository.


範例:git 克隆 https://github.com/user/repo.git

4. git 狀態

Purpose: Show the working directory and staging area status.


範例:git 狀態

5. git加入

Purpose: Add file contents to the index (staging area).


範例: git add . (新增所有檔案)

6. git 提交

Purpose: Record changes to the repository.


範例: git commit -m "提交訊息"

7. git推送

Purpose: Update remote refs along with associated objects.


範例: git push origin main

8. git 拉取

Purpose: Fetch from and integrate with another repository or local branch.


範例: git pull origin main

9. git分支

Purpose: List, create, or delete branches.


範例:gitbranchnew-branch(建立新分支)

10. git 結帳

Purpose: Switch branches or restore working tree files.


範例: git checkout new-branch (切換到分支)

11. git 切換

Purpose: Switch branches.


範例:git 切換新分支

12. git 執行

Purpose: Join two or more development histories together.


範例: git merge new-branch (將 new-branch 合併到目前分支)

13. 吉特狐狸

Purpose: Reapply commits on top of another base tip.


範例:git rebase main

14. git 日誌

Purpose: Show commit logs.


範例: git log --oneline

15. git 差異

Purpose: Show changes between commits, commit and working tree, etc.


範例:git diff(顯示未暫存的變更)

16. git顯示

Purpose: Show various types of objects.


範例: git show HEAD (顯示上次提交的變更)

17. git 存儲

Purpose: Stash the changes in a dirty working directory away.


範例:git 存儲

18. git stash 流行

Purpose: Apply the changes recorded in the stash to the working directory.


範例:git stash pop

19. git 清理

Purpose: Remove untracked files from the working directory.


範例:git clean -fd

20. git 遠程

Purpose: Manage set of tracked repositories.


範例: git Remote add origin https://github.com/user/repo.git

21. git 獲取

Purpose: Download objects and refs from another repository.


範例:git fetch origin

22. git遠程-v

Purpose: Show the URLs that a remote name corresponds to.


範例:git遠端-v

第 23 個 git 日

Purpose: Create, list, delete, or verify a tag object.


範例: git tag -a v1.0 -m "版本 1.0"

24. git push origin --標籤

Purpose: Push all tags to the remote repository.


範例: git push origin --tags

25. git重置

Purpose: Reset current HEAD to the specified state.


範例: git reset --hard HEAD~1 (重設為上一次提交)

26. git 恢復

Purpose: Create a new commit that undoes the changes from a previous commit.


範例:git 恢復 HEAD

27. git checkout——

Purpose: Discard changes in the working directory.


範例: git checkout -- file.txt (放棄 file.txt 中的變更)

28. git 櫻桃挑選

Purpose: Apply the changes introduced by some existing commits.


範例:gitcherrypick

29. git分支-d

Purpose: Delete a branch.


範例: git 分支 -d 分支名稱

30. git分支-D

Purpose: Force delete a branch.


範例: git 分支 -D 分支名稱

31. git merge --no-ff

Purpose: Create a merge commit even when the merge resolves as a fast-forward.


範例: git merge --no-ff 新分支

32. git rebase -i

Purpose: Start an interactive rebase.


範例: git rebase -i HEAD~3

33. git diff --staged

Purpose: Show changes between the index and the last commit.


範例: git diff --staged

34. git 責備

Purpose: Show what revision and author last modified each line of a file.

Example: git blame file.txt

35. git log --圖

Purpose: Show a graph of the commit history.


範例: git log --graph --oneline

36. git reflog

Purpose: Show a log of all references.


範例:git reflog

37. git 儲存列表

Purpose: List all stashes.


範例:git 儲存列表

38. git stash 應用

Purpose: Apply a stash to the working directory.


範例:git stash apply stash@{1}

39. git stash drop git stash drop

Purpose: Remove a single stash entry from the list of stashes.


範例:git stash drop stash@{1}

40. git遠端顯示

Purpose: Show information about the remote repository.


範例:git 遠端顯示原點

41. git 遠端 rm

Purpose: Remove a remote.


範例: git 遠端 rm 原點

42. git pull --rebase

Purpose: Fetch and rebase the current branch on top of the upstream branch.


範例: git pull --rebase origin main

43. git fetch --全部

Purpose: Fetch all remotes.

Example: git fetch --all

44. git 二分法

Purpose: Use binary search to find the commit that introduced a bug.


範例: git bisect start

45. git 子模組

Purpose: Initialize, update, or inspect submodules.


範例: git 子模組更新 --init

46. git 存檔

Purpose: Create an archive of files from a named tree.


範例: git archive --format=tar HEAD > archive.tar

47. git 短日誌

Purpose: Summarize git log output.


範例:git Shortlog -s -n

48. git 描述

Purpose: Give an object a human-readable name based on an available ref.

Example: git describe --tags

49. git rev 解析

Purpose: Parse revision (or other objects) and retrieve its hash.


範例:git rev-parse HEAD

50. git標籤-d

Purpose: Delete a tag from the local repository.


範例:git 標籤 -d v1.0

51. git checkout -b git checkout -b

Purpose: Create and switch to a new branch.


範例: git checkout -b 新分支

52. git push origin --刪除

Purpose: Delete a remote branch.


範例: git push origin --delete 分支名稱

53. git 櫻桃

Purpose: Find commits not merged upstream.


範例:gitcherry-v

54. 去 rm

Purpose: Remove files from the working tree and from the index.


範例: git rm file.txt

55. 去MV

Purpose: Move or rename a file, directory, or symlink.


範例: git mv oldname.txt newname.txt

.56 git 重置 HEAD

Purpose: Unstage changes.


範例: git Reset HEAD file.txt

57. git 日誌 -p

Purpose: Show changes over time for a specific file.


範例: git log -p file.txt

58. git diff --緩存

Purpose: Show changes between the index and the last commit (same as --staged).


範例: git diff --cached

59. git 應用

Purpose: Apply a patch to files and/or to the index.


範例:git apply patch.diff

60. git 格式補丁

Purpose: Prepare patches for e-mail submission.


範例:git format-patch -1 HEAD

61. 早上去

Purpose: Apply a series of patches from a mailbox.


範例: git am < patch.mbox

62. gitcherry-pick--繼續

Purpose: Resume cherry-picking after resolving conflicts.


例: gitcherry-pick --繼續

63. git fsck

Purpose: Verify the connectivity and validity of objects in the database.


範例:git fsck

64. git GC

Purpose: Cleanup unnecessary files and optimize the local repository.


範例:git GC

65. git 修剪

Purpose: Remove unreachable objects from the object database.


範例:git 修剪

66. git 筆記

Purpose: Add or inspect object notes.


範例: gitnotesadd-m“註解訊息”

67. git 改變了什麼

Purpose: Show what changed, similar to git log.


範例:git Whatchanged

**68。 git show-branch **

Purpose: Show branches and their commits.


範例:git show-branch

69. git 驗證標籤

Purpose: Check the GPG signature of tags.


範例:git verify-tag v1.0

70. git顯示參考

Purpose: List references in a local repository.


範例:git show-ref

LinkedIn Account領英

Twitter Account推特

圖片來源:圖片來自LinkedIn


原文出處:https://dev.to/iamcymentho/git-commands-for-software-engineers-51n8


共有 0 則留言


精選技術文章翻譯,幫助開發者持續吸收新知。

阿川私房教材:學程式,拿 offer!

63 個專案實戰,直接上手!
無需補習,按步驟打造你的面試作品。

立即解鎖你的轉職秘笈