Git command uses a local build git remote library and Associates, commit git remote library is empty
The general process is as follows: (The remote library is empty means that there is nothing in Git's remote library, if there is no empty readme, you need to use another method)
- Git init
———— initialize a git repository locally,
- git add *
———— add all the files in the current folder to the buffer
- Git commit-m "Zhushi"
———— Submit the file you added in the previous step to the local library,
- Git remote add origin git address
For example (git remote add origin [email protected]:shijinliang/sjltest.git)
———— associates the first-step git repository with the Git remote.
- Git push Origin Master
———— commit the version of the commit just now to the remote side of the association.
When there are files in the Git remote repository
The general flow is as follows:
git clone git address
For example (git clone [email protected]:shijinliang/sjltest.git)
———— Download the contents of the remote side to the local, after downloading, need to go into the folder to do the next step, the git command line must be in the current project directory in the folder or its subfolders under the execution (. Git folder is a hidden folder, Need to set the computer to be visible for hidden folders)
- git add *
———— put the files that need to be submitted in the directory of the Git library, execute this command, add all the files to the buffer,
- Git commit-m "Comments"
———— explain it with the above
- Git push Origin Master
———— explain it with the above
This will put the project up.
git fetch (git pull)
During the development process (local already has remote terminal code time), if need to push or modify code before, pull first, let local file and remote library belong to the same version, then can push (commit).
At the same time, when the development of a module or a function of the time, can commit once, only commit, not push,commit submitted to the local, and then when needed, direct push, All previous commits (the commit between the last push and the push) are pushed up.
Other git status
View current local file status, generally divided into two categories,
Changes not staged for commit:
(use "git add ..." To update what'll be committed)
(use "Git checkout– ..." to discard changes in working directory)
Modified:test/main.m
untracked files:
(use "git add ..." to include in what'll be committed)
Test/main2.m
The above two, the first shows that the local files are modified (these files are in the library), the second is the library does not have files, local, the above hints are written very clearly,
The first is that you can update the corresponding file to the buffer using git add "test/main.m" or git checkout– "test/main.m".
The second option is to add the update only by using git add "test/main2.m".
(The address in the middle of git add/checkout quotes above is consistent with the address given in git status above.) )
Git stash
This command is generally used in the local file modification, but now do not want to commit the case, and now need to switch to another branch or need to update other code (local changes do not commit, this time the pull (update) will prompt error), you can use the Git stash save
The file temporarily has a staging area, and then the local code is exactly the same as the version before the modification, you can do your own other operations,
After doing other work, you need to continue the development of the previous, this time through the Git stash pop to extract the staging area files, continue to develop.
- Of course, staging area can be saved many times, this self-understanding,
–git Stash Save/git Stash Pop –
. gitignore
Ignore a list of files, this folder can be created at the time of the GIT site to build the library, or in the local through the file save one, can play a good role, the unnecessary to submit the file ignored
Losing version control
The above. Gitignore is the practice of putting a local file, not committing it to the library, but what if the file in the library is modified and you don't want to commit it, and you want it to lose version control, by the following method:
git update-index–assume-unchanged file name
(The following file name includes the path and suffix, it is recommended to use the command under the file's current path, so the file name does not include the path.) )
The git update-index–no-assume-unchanged file name is similar to the above.
Skills
- Chinese in the command line is generally displayed in the octal character encoding, you can use the command to modify: Git Config–global core.quotepath false.
(by setting the GIT config variable core.quotepath to false, you can solve the problem of displaying the Chinese file name in these git command outputs.)
- 2
Cond!
The use of GIT commands