This article refers to git-v2.19.1
Files in.gitignore are not ignored
why
- Grammar mistakes
You can check and repair the following syntax rules:
# This is a comment -- and will be ignored by Git
*.a Ignore all files ending in.a! lib.a# except lib.a
/TODO Only TODO files in the project root directory are ignored, excluding subdir/TODO
build/ Ignore all files in the build/ directory
doc/*.txt # ignore doc/notes.txt but not doc/server/arch.txt
**/foo # ignore all files or folders foo
abc/** All files in the ABC path are ignoredA / * * / bA /b, a/x/b, A /x/y/b, etc
Copy the code
- Local file cache
Git index file: Git /index is the file into which Git inputs information after any action is performed in the workspace. When using git status queries, git uses index to compare the latest version of the repository to determine which files are in what state. (Index is retrieved by the contents of the file.)
Here’s why:
A gitignore file specifies intentionally untracked files that Git should ignore.
Files already tracked by Git are not affected; see the NOTES below for details.
To stop tracking a file that is currently tracked, use git rm --cached.
Copy the code
Git has four states (Untracked/Unmodified/Modified/Staged). From either state to Untracked you have to perform an action that is deleted from a Git repository but not from a local file.
Git ls-files command to view the contents of the version library.
Refer to the following repair method:
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
Copy the code
The resources
2. Push fails
Error as follows:
error: src refspec xx does not match any.
error: failed to push some refs to ‘xxxx.git’
Solution:
git push origin HEAD:xx
Copy the code
Description of common commands
Pull the remote branch to the local
git checkout [-q] [-f] [-m] [[-b|-B|--orphan] <new_branch>] [<start_point>] <start-point> The new branch head will point to this commit. It may be given as a branch name, a commit-id, or a tag. If this option is omitted, the current HEAD will be used instead. eg: Git checkout -b dev origin/dev Git push origin <branch_name> If the branch does not have the branch, the branch will be created.Copy the code
Push the branch
Push local BRANCH A to remote branch B
git push origin A:B
Copy the code
Git push origin :experimental deletes the branch. Find a ref that matches experimentalin the origin repository (e.g. refs/heads/experimental), and delete it.
Copy the code
git checkout A
git push origin A
Copy the code
Push local BRANCH A to remote branch B
git checkout A
git push origin A:B
Copy the code
Delete the branch
Delete a local branch: git branch-d<branch_name> Forcibly delete a local branch: git branch -d <branch_name> Delete a remote branch: git push origin-d <branch_name>
Copy the code
Merging branches
Git merge A branch into B branchCopy the code
Resolve the conflict
Conflict may occur during merging. Open Unmerged files
<<<<<<< HEAD:index.html
<div id="footer">contact : [email protected]</div>
=======
<div id="footer"> please contact us at [email protected] </div> >>>>>>> iss53:index.html ======= divides the conflict into two parts. The top half is from <<<<<<< HEAD:index.html The content of the current branch starts at the bottom half and ends at >>>>>>> iss53:index.htmlCopy the code
Resolve the conflict manually and commit.
The resources
Send the merge request
Access to branch
Git pull is equivalent to git fetch and git mergeCopy the code
Update the remote trace branch
git fetch origin
The above command copies all branches from the remote refs/heads/ namespace and stores them in the local refs/remotes/ Origin/namespace, unless the branching.<name>. Fetch option is used to specify a non-default Refspec. It is important to note that when a new remote trace branch is captured, an editable copy (copy) is not automatically generated locally. In other words, in this case, there won't be a new xx branch - just an origin/xx pointer that can't be modified.Copy the code
git fetch origin dev
Pull the dev branch locally
Storage and cleaning
Git stash equivalent to git Stash push --keep-index tells Git not to store things that have been temporarily stored through the git add command. If you do not add this parameter, git add will be stored together. --include-untracked or -u tags. Git also stores any untracked files that are created. By default, git Stash stores only files that are already in the index. -- Patch Git doesn't store everything that has been changed, but interactively prompts you for changes that you want to store and those that need to be saved in your working directory. Git stash branch <branch_name> Create a new branch, check out the commit where the stash work is,Copy the code
-
When you switch branches, you need to commit your work before, so store your changes. To push the new stash onto the stack, run git Stash or Git Stash Save.
-
The git stash save –keep-index option tells Git not to store things that have been temporarily stored through the git add command. If you do not add this parameter, git add will be stored together.
-
The Git Stash apply reapplies the work you just stored. If you want to apply one of the older repositories, you can specify it by name: git stash apply stash@{2}. Git stash apply –index
-
Git stash pop applies and is removed from the stack, equivalent to git stash apply and then git stash drop stash@{latest}.
-
Git Stash clear Clears all stash. Git stash drop stash@{1} Removes the specified stash.
-
Look at your stash list.
-
Git Stash Push vs. Git Stash Save ‘stash save’ differs from “stash push” in that it cannot take pathspecs, and any non-option arguments form the message.
Git stash push can be followed by a path, and git stash save cannot be followed by a path. In addition, you can add -m –message to git Stash push, but not -m to git Stash save.
- The difference between Git Stash pop and Git Stash apply
Explanation and differentiation of terms
Git’s “master” branch is not a special branch. It’s just like any other branch. The reason almost every repository has a master branch is because git init creates it by default and most people don’t bother to change it.
What does remote/Origin/HEAD/refs stand for respectively
origin
When an item is cloned from a remote repository, the clone command automatically names it Origin, pulls all of its data, creates a pointer to its master branch, and locally names it Origin /master. Git will also give you a local master branch that points to the same place as origin’s master branch, so you have something to work on.
The remote repository name “Origin”, like the branch name “master”, has no special meaning in Git. While “master” is the default starting branch name when you run Git init, simply because it’s widely used, “Origin” is the default remote repository name when you run Git Clone. If you run Git clone -o booyah, your default remote branch name will be booyah/master.
HEAD
How does Git know which branch it is currently on? It’s also simple, it has a special pointer called HEAD. Note that it is completely different from the concept of HEAD in many other version control systems, such as Subversion or CVS. In Git, HEAD is a pointer to the current local branch.
Origin The difference between origin master and Origin/Master
git push origin serverfix
Git serverfix branch name will be launched for the refs/heads/serverfix: refs/heads/serverfix means “push on local serverfix branch to update the remote warehouse serverfix branch”
git difftool –tool-help git difftool –tool=
Git DiffTool visually compares the difference between the current working directory and the temporary snapshot. (Available after V2.2.0)