CMD / PowerShell common commands git common commands


1. Create a new folder: MKDIR DirectoryName
2. New file:
CMD: type nul > filename (empty file)
powershell: new-item fileName -type file
Echo “content” > filename (file with content)

3. Delete folder: CMD: del DirectoryName
powershell: rmdir directoryName
4. Delete file: CMD: del filename
powershell:rm/del fileName

5. Rename file / folder: CMD: Rename old newfilename / DirectoryName
powershell: mv old newFileName / mv directoryName newDirectoryName

6. Open the file: PowerShell: get content filename

7. Empty panel: clear
8. View the list of all files in the current folder: dir

Local operation:
Git status: view status (there are three statuses: local untracked, staged and submitted)
Git add: add locally to the temporary storage to track files
Git diff: the difference between local files and temporary files
Git diff — cached: the difference between temporary and last submitted files
Git difftool / git difftool — cached: use VIM tool to compare files (: QA + enter exit)
Git commit – M “description”: submit the temporary file to the version library. If you forget to add comments:: WQ exit the add comments status
Git commit — amend – M “description content”: patch the version that was not pushed in the last submission (the last submission record ID will be changed, and the description information will be overwritten)
Git RM filename: removes the local file and UN tracks it
Git RM filename — cached: delete the trace of the file and keep the local file
Git MV oldname newname: rename a file (equivalent to deleting a file locally, adding a file, and then adding; the file is in a state without a status icon and is actually in the temporary storage area)
Git log / git log – Number: View submission records, – number view recent times
Git log — patch – Number: view the detailed submission information of each file
Git log — stat – Number: view and modify the file name list submission information
Git log — author = “author”: view a person’s submission record
Git show version number: view the detailed file modification submission information of a certain time
Git reflog: view all operation records; The difference between git log and git log is that git log only commits records
q: Exit view history
Git commit — amend: overwrite the submission and add the uncommitted files to the previous submission
Git restore head filename: cancel the temporary file (in the prompt of GIT status)
Git checkout — filename: cancels the modification of the local file that is not temporarily stored. In fact, it overwrites the local file with the latest submitted version (in the prompt of GIT status)
Git checkout.: cancel local uncommitted modifications

Remote operation:
Git remote: get all remote warehouse information
Git remote – V: get the abbreviations and URL information of all remote warehouses
Git remote show remotename: view the details of a remote warehouse
Git remote add remotename URL: add remote warehouse
Git remote rename oldname newname: modify the short name of the remote warehouse
Git remote RM remotename: remove a remote warehouse
git remote set-url origin http://xxxxxx Modify remote address
Git clone: Clone remote warehouse content to local
Git branch: view current branch
Git branch – A: view all branches, local and remote
Git branch – V: view the local branch and display the latest submission information
Git checkout branch: switch branches
git fetch : update the code from the remote warehouse, which can be the URL or the name when adding the remote warehouse, or it can be omitted; This operation will not automatically merge or modify local files, but needs to be merged manually.
Git pull: update the code from the remote warehouse. Unlike git fetch remote, it will automatically attempt to merge to the current branch (compare and merge with the local committed version Library), which is equivalent to git fetch + git merge. Theoretically, before executing this command, you need to check the current status, submit the files of add and commit to the local warehouse, and then execute this command to pull and merge with the local warehouse.
Git push: push local content to remote warehouse
Git stash save message: stage some unmodified files of the current branch
Git stash list: list of all temporary files
Git stash apply stash @{num}: check out a temporary file to the working directory

Git RM — cached XXX: delete a file from the added file

Git FAQ:
1. Merge a submission of a branch into another branch?
Git log: check the version number of a submission you want to merge (for example, submitted in the dev branch)
Git checkout test: switch to the branch you want to merge into
Git cherry pick version number: merge a submission of other branches into the current branch
Git push: submit to remote (previous operations were in the local warehouse)

2. After commit, you want to add new modifications and submit them together?
git add –all
Git commit – M “first commit”
(after adding new modifications)
git add –all
Git commit — amend – M “two final descriptions”

3. If the current branch has not been modified, switch to other branches, and other branches cannot see the unmodified file?
Git stash save ‘description’: when the test1 branch is not added, the unmodified files are temporarily stored
git checkout test2
Test2 branch operation file, operation completed
git checkout test1
Git stash list: view the list of all temporary files
Git stash apply stash @{num}: check out a cache file to the working directory (according to the prompt, sometimes: git stash apply Num)

4. Pull down the remote code without submitting the current change:
Git stash save ‘description’
git pull
git stash list
Git stash apply stash @{num} (sometimes: git stash apply Num)

4. View the modification submission record of a file:
Git log – P file name / / all submission records are displayed
Git show version number and file name. / / view the details of a file in a version

5. Submit only partially modified or added Codes:

Git status – s view warehouse status

Git add Src / components / file name add the file name to be submitted (add path — refer to the file path printed by git status)

Git stash – U – K ignores other files and hides the modified files so that files that have not been added will not be submitted when submitting

Git commit – M “where did you make changes to write…”

Git pull pull merge

Git push to remote warehouse

Git stash pop restores previously ignored files (a very important step)

Recommended Today

Heavyweight Tencent cloud open source industry’s first etcd one-stop governance platform kstone

​ Kstone open source At the kubecon China Conference held by CNCF cloud native foundation on December 9, 2021,Tencent cloud container tke team released the open source project of kstone etcd governance platform. KstoneIt was initiated by the TKE team of Tencent cloud containerCloud native one-stop etcd governance project based on kubernetes。 The project originates […]