Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
appwiki:git [2024/04/11 05:33] – [Command Git cmds] ying | appwiki:git [2024/04/11 09:04] – ying | ||
---|---|---|---|
Line 7: | Line 7: | ||
====== Command Git cmds ====== | ====== Command Git cmds ====== | ||
+ | The Three States of Git | ||
+ | * **Modified**: | ||
+ | * **Staged**: A modified file becomes staged when you **add it** to your staging area. Here, Git has it marked as ready to be committed in the next snapshot. This means you've told Git to include the updates from this file in the upcoming commit. | ||
+ | * **Committed**: | ||
+ | |||
+ | Cmds | ||
* start the git-cmd.exe and now you are in a cmd with git built-in, or add git path to your cmd session: < | * start the git-cmd.exe and now you are in a cmd with git built-in, or add git path to your cmd session: < | ||
* create a default user if you have not <code dos> | * create a default user if you have not <code dos> | ||
Line 12: | Line 18: | ||
git config --global user.email " | git config --global user.email " | ||
</ | </ | ||
+ | * list config <code dos>git config --list</ | ||
* create a project folder <code dos> | * create a project folder <code dos> | ||
cd SuperWebProj | cd SuperWebProj | ||
touch index.html | touch index.html | ||
+ | </ | ||
+ | * create ignore list inside git directory, create .gitignore file <code dos> | ||
+ | # ignore folder, ignore type of files | ||
+ | __pycache__/ | ||
+ | *.py[cod] | ||
+ | |||
+ | # ignore build folder | ||
+ | build/ | ||
</ | </ | ||
* cd to the folder where you want to create a repo <code dos>git init</ | * cd to the folder where you want to create a repo <code dos>git init</ | ||
Line 24: | Line 39: | ||
* check status <code dos>git status</ | * check status <code dos>git status</ | ||
* optional: you can change branch name like <code dos>git branch -m master main</ | * optional: you can change branch name like <code dos>git branch -m master main</ | ||
- | * add everything in the directory that is changed <code dos>git add .</ | + | * add everything in the directory that is changed |
+ | * all new and modified files: | ||
+ | * all new and modified + deleted files <code dos>git add -A</ | ||
+ | * all modified + deleted files <code dos>git add -u</ | ||
* to view change log <code dos>git log</ | * to view change log <code dos>git log</ | ||
* use git to zip folder <code dos> | * use git to zip folder <code dos> | ||
git archive --format=zip -o project_code.zip HEAD project_code | git archive --format=zip -o project_code.zip HEAD project_code | ||
</ | </ | ||
+ | * git download a project: cd to root of your project folders, (note: clone will create root folder of the git project, best no space, AnBn style naming) <code dos> | ||
+ | git clone https:// | ||
+ | </ | ||
+ | * git remote source for fetch and push, (this only deal with remote repo), check remote source <code dos> | ||
+ | git remote -v | ||
+ | </ | ||
+ | * git list branch, | ||
+ | * both local and remote branch< | ||
+ | * both local branch< | ||
+ | * git check all changes to files in detail, this is before changes added (not yet commit) <code dos>git diff</ | ||
+ | * always get source update before push <code dos>git pull origin branch-name | ||
+ | git push origin branch-name | ||
+ | </ | ||
+ | * create branch for a feature or a issue <code dos>git branch export-feature</ | ||
+ | * switch branch <code dos>git checkout export-feature</ | ||
+ | * push to remote repo <code dos>git push -u origin export-feature</ | ||
+ | * merge a feature branch into main <code dos>git checkout main | ||
+ | git merge export-feature | ||
+ | </ | ||
+ | * to check which feature branch has been merged into main before, checkout to main, then <code dos>git branch --merge</ | ||
+ | * to check which feature branch has NOT been merged into main, <code dos>git branch --no-merged</ | ||
+ | * for already merged branch shows in --merge cmd, you can safely delete those feature branch, as they are already part of main. | ||
Extra Tips: | Extra Tips: | ||
- | * you can use vscode to open the folder project (the one with .git hidden folder), vscode will auto know it is a git project and it has some built-in tool to help you instead of using the git cmd | + | * you can use vscode to open the folder project (the one with .git hidden folder), vscode will auto know it is a git project and it has some built-in tool to help you instead of using the git cmd <code dos>git branch -d export-feature</ |
* you may need to set git.exe path if you use above portable one, | * you may need to set git.exe path if you use above portable one, | ||
* go File > Preference > setting , search git path, click edit setting.json, | * go File > Preference > setting , search git path, click edit setting.json, | ||
* if you want more help, you can use Github Desktop app, which you dont have to use their github service, you can use add your local disk project folder, you can manage all the git cmd in a visual way, like compare difference and make commit | * if you want more help, you can use Github Desktop app, which you dont have to use their github service, you can use add your local disk project folder, you can manage all the git cmd in a visual way, like compare difference and make commit |