Article^ Parent
Git 笔记
Date: | 2020-09-05 00:00:00 |
Description: | Git 使用笔记。 |
Keywords: | Git, 使用例子 |
Category: | engineering_technology/computer/software/software_development/git |
Tag: | git |
Link: | https://www.diewuxi.com/blog/article/98.html |
Changelog
* 2023-01-05
* Add: Remote.
* Add: Push.
* 2022-05-22
* Add: Undo add.
* 2020-09-27
* Add: rebase change old commit
* Add: stash
* Add: commit
* 2020-09-05
* Done
Tag
Add:
git tag -a v1.4.0 -m "my version 1.4.0"
git tag -a v1.2.0 -m "my version 1.2.0" <early commit object>
Delete:
git tag -d v1.4.0
Show:
git tag --list
git show v1.4.0
Push:
git push origin v1.0.0
git push origin --tags
Check:
git check v1.4.0
Branch
Syntax
git branch [--color[=<when>] | --no-color] [--show-current]
[-v [--abbrev=<n> | --no-abbrev]]
[--column[=<options>] | --no-column] [--sort=<key>]
[--merged [<commit>]] [--no-merged [<commit>]]
[--contains [<commit>]] [--no-contains [<commit>]]
[--points-at <object>] [--format=<format>]
[(-r | --remotes) | (-a | --all)]
[--list] [<pattern>...]
git branch [--track | --no-track] [-f] <branchname> [<start-point>]
git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>]
git branch --unset-upstream [<branchname>]
git branch (-m | -M) [<oldbranch>] <newbranch>
git branch (-c | -C) [<oldbranch>] <newbranch>
git branch (-d | -D) [-r] <branchname>...
git branch --edit-description [<branchname>]
Show
git branch --list --all -v
git branch --show-current
Set upstream branch
git branch --set-upstream-to=origin/main main
Add
Undo add
git reset <file>
Commit
修改最近一次提交的提交信息,那么很简单:
git commit --amend
在满意之前不要推送你的工作
Remote
Syntax
git remote [-v | --verbose]
git remote add [-t <branch>] [-m <master>] [-f] [--[no-]tags] [--mirror=(fetch|push)] <name> <url>
git remote rename <old> <new>
git remote remove <name>
git remote set-head <name> (-a | --auto | -d | --delete | <branch>)
git remote set-branches [--add] <name> <branch>...
git remote get-url [--push] [--all] <name>
git remote set-url [--push] <name> <newurl> [<oldurl>]
git remote set-url --add [--push] <name> <newurl>
git remote set-url --delete [--push] <name> <url>
git remote [-v | --verbose] show [-n] <name>...
git remote prune [-n | --dry-run] <name>...
git remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
Add remote
git remote add origin https://github.com/cddwx525/diewuxi.git
git remote set-head origin main
Push
git push [--all | --mirror | --tags] [--follow-tags] [--atomic] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
[--repo=<repository>] [-f | --force] [-d | --delete] [--prune] [-v | --verbose]
[-u | --set-upstream] [-o <string> | --push-option=<string>]
[--[no-]signed|--signed=(true|false|if-asked)]
[--force-with-lease[=<refname>[:<expect>]] [--force-if-includes]]
[--no-verify] [<repository> [<refspec>...]]
Stash
- List stashs:
git stash list [option]
- Show:
git stash show [<stash>]
- Save to stash:
git stash [save [-p|--patch] [-k|--[no-]keep-index] [-u|--include-untracked] [-a|--all] [-q|--quiet] [<message>]]
Simple use git stash
in common use.
- Apply:
git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]
pop: apply and remove this stash.
Rebase
Common
Change previous commit
- Stash current working or stage change if have
git stash save
- Find the commit
git log
- Rebase -i
git rebase -i HEAD~<number>
or
git rebase -i <commit-hash>
- Edit command list
change
pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
to
edit f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file
so you will go to f7f3f6d state, then save the file, you will then exec it immediately.
- Make your changes, as if time go back to just commit the f7f3f6d
Re get previous files:
git stash pop
Add files:
git add <file>
Append commit:
git commit --amend
then modify commit or f7f3f6d, save and exit, the commit is modified successfully.
- Coninue rebase process, back to future
git rebase --continue
- Done, now have put something to back time
Last modified: 2023-01-05
Comments [0]
There is no comments now.