? ǰ��
Git���ִ����������в��ɻ�ȱ�İ汾���ƹ��ߡ��������dz�ѧ�����о���Ŀ����ߣ�����Git���DZر����ܡ����Ľ�������㿪ʼ��ϵͳѧϰGit�ĸ��ֲ��������ʵ����
? ѧϰĿ��
ͨ������ѧϰ���㽫���գ�
- Git�Ļ����������ԭ��
- ����Git�����ʹ�÷���
- ��֧�����ͺϲ�����
- Զ�ֿ̲�IJ���
- �����ͻ�ļ���
- Git�������̺����ʵ��
? Git��������
ʲô��Git��
Git��һ���ֲ�ʽ�汾����ϵͳ����Linux֮��Linus Torvalds�����������������ص㣺
- �ֲ�ʽ��ÿ�������߶��������Ĵ�����ʷ
- ��Ч�����ٵķ�֧�����ͺϲ�
- ��ȫ��ʹ��SHA-1��ϣȷ������������
- �����֧�ֶ��ֹ�������
Git����������
1 2 3 4 5 6 7
| ������ (Working Directory) �� git add �ݴ��� (Staging Area) �� git commit ���زֿ� (Local Repository) �� git push Զ�ֿ̲� (Remote Repository)
|
?? Git��������
1. ��ʼ��������
1 2 3 4 5 6 7 8 9
| git init
git config --global user.name "�������" git config --global user.email "�������"
git config --list
|
2. ���������
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| git status
git add filename.txt git add . git add *.js
git commit -m "�ύ��Ϣ" git commit -am "���Ӳ��ύ"
git log git log --oneline git log --graph
|
3. �ļ�״̬����
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git checkout -- filename.txt
git reset HEAD filename.txt
git reset --soft HEAD~1 git reset --hard HEAD~1
git diff git diff --cached git diff HEAD
|
? ��֧����
��֧��������
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| git branch git branch -r git branch -a
git branch feature-login git checkout -b feature-login
git checkout main git switch main
git checkout main git merge feature-login
git branch -d feature-login git branch -D feature-login
|
��֧�ϲ�����
1 2 3 4 5 6 7 8
| git merge feature-branch
git merge --no-ff feature-branch
git rebase main
|
? Զ�ֿ̲����
Զ�ֿ̲����
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| git remote add origin https://github.com/username/repo.git
git remote -v
git push origin main git push -u origin main
git pull origin main git fetch origin
git clone https://github.com/username/repo.git
|
Զ�̷�֧����
1 2 3 4 5 6 7 8
| git push origin feature-branch
git push origin --delete feature-branch
git checkout -b local-branch origin/remote-branch
|
? ������
1. ����(Stash)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| git stash git stash save "������Ϣ"
git stash list
git stash apply git stash apply stash@{1}
git stash drop git stash clear
|
2. ��ǩ����
1 2 3 4 5 6 7 8 9 10 11
| git tag v1.0.0 git tag -a v1.0.0 -m "�汾1.0.0"
git tag git show v1.0.0
git push origin v1.0.0 git push origin --tags
|
3. ���
1 2 3 4 5 6 7 8 9
| git submodule add https://github.com/user/repo.git path/to/submodule
git submodule init git submodule update
git submodule update --remote
|
? ��ͻ���
�ϲ���ͻ����
�����ֳ�ͻʱ��Git�����ļ��б�dz�ͻ����
1 2 3 4 5
| <<<<<<< HEAD ��ǰ��֧������ ======= Ҫ�ϲ���֧������ >>>>>>> feature-branch
|
������裺
- �ֶ��༭��ͻ�ļ�
- ɾ����ͻ���
- ���ӵ��ݴ�����
git add filename
- �ύ�ϲ���
git commit
���ó�ͻ�������
1 2 3 4 5 6 7 8 9 10 11
| git status
git mergetool
git merge --abort
git rebase --abort
|
? Git��������
1. Git Flow
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| git checkout -b feature/new-feature develop
git checkout develop git merge --no-ff feature/new-feature git branch -d feature/new-feature
git checkout -b release/1.0.0 develop
git checkout main git merge --no-ff release/1.0.0 git tag v1.0.0 git checkout develop git merge --no-ff release/1.0.0
|
2. GitHub Flow
1 2 3 4 5 6
| git checkout -b feature-branch
git push origin feature-branch
|
? ���ʵ��
�ύ��Ϣ�淶
1 2 3 4 5 6 7 8
| feat: �����û���¼���� fix: ��������֤bug docs: ����API�ĵ� style: ��ʽ������ refactor: �ع��û�ģ�� test: ���ӵ�Ԫ���� chore: ����������
|
��֧�����淶
1 2 3 4
| feature/user-authentication bugfix/login-error hotfix/security-patch release/v1.2.0
|
.gitignore����
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
| # ����Ŀ¼ node_modules/ vendor/
# ������� dist/ build/ *.min.js
# ��־�ļ� *.log logs/
# �������� .env .env.local
# IDE�ļ� .vscode/ .idea/ *.swp
# ϵͳ�ļ� .DS_Store Thumbs.db
|
? ����������
1. ��������
1 2 3 4 5 6 7 8
| git reset --soft HEAD~1
git commit --amend -m "�µ��ύ��Ϣ"
git checkout -- filename
|
2. �����ֿ�
1 2 3 4 5 6 7
| git clean -f git clean -fd git clean -n
git gc
|
3. �鿴��ʷ
1 2 3 4 5 6 7 8 9
| git log -p filename
git blame filename
git log --grep="�ؼ���" git log --author="������"
|
?? Git��ȫ
1. ǩ���ύ
1 2 3 4 5 6
| git config --global user.signingkey YOUR_GPG_KEY git config --global commit.gpgsign true
git commit -S -m "ǩ���ύ"
|
2. ������Ϣ����
1 2 3 4
| git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch secrets.txt' \ --prune-empty --tag-name-filter cat -- --all
|
? ѧϰ��Դ
�Ƽ���Դ
ʵ�ù���
- GUI����: GitKraken, SourceTree, GitHub Desktop
- ��������ǿ: Oh My Zsh, Git����
- ������ϰ: Katacoda Git�γ�
? �ܽ�
Git���ִ��������ɻ�ȱ�Ĺ��ߣ���������Ҫ����ѧϰ��ʵ�����ϡ��ӻ�����add��commit��push��ʼ����ѧϰ��֧��������ͻ����ȸ����ܡ�
��ס��ЩҪ�㣺
- Ƶ���ύ�������ύ��������
- д�������ύ��Ϣ
- ����ʹ�÷�֧���й��ܿ���
- ����ͬ��Զ�ֿ̲�
- �������ⲻҪ�ţ�Git�������в��������Գ���
������ϰ����ᷢ��Git�����ǰ汾���ƹ��ߣ�������߿���Ч�ʵ�������
? С��ʿ: ������ѧϰ�����д���һ����ϰ�ֿ⣬���ֲ���ÿ����������ܸ��õ�����Git�Ĺ���ԭ����
��������Ƽ�: