国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home Development Tools git Summary of common Git commands

Summary of common Git commands

Jun 06, 2019 pm 04:04 PM
git command

Summary of common Git commands

Common git commands are:

git init

Create a new repo locally and enter In a project directory, executing git init will initialize a repo and create a .git folder under the current folder.

git clone

Get the remote Git repo corresponding to a url and create a local copy.

The general format is git clone [url].

The cloned repo will start with the last slash of the url. Name it and create a folder. If you want to specify a specific name, you can specify it with git clone [url] newname.

git status

Query the status of the repo.

git status -s: -s means short, the output mark of -s will have two columns, the first column is for the staging area, and the second column is for the working directory In terms of.

git log

show commit history of a branch.

git log --oneline --number : Each log only displays one line, showing number.

git log --oneline --graph: can graphically represent the branch merge history.

git log branchname can display a specific branch log.

git log --oneline branch1 ^branch2, you can view the commits in branch 1 but not in branch 2. ^ means to exclude this branch (you may need to add quotation marks to ^branch2 under Windows).

git log --decorate will display tag information.

git log --author=[author name] can specify the author's submission history.

git log -- since --before --until --after Filter logs based on commit time.

--no-merges can exclude merge commits.

git log --grep Filter based on commit information log: git log --grep=keywords

By default, git log --grep --author is an OR relationship, that is, it will be returned if one of them is met. If you want them to be an AND relationship, you can Add the --all-match option.

git log -S: filter by introduced diff.

For example: git log -SmethodName (note that there is no equal sign between S and the following words separated).

git log -p: show patch introduced at each commit.

Each submission is a snapshot, and Git will calculate the diff of each submission as A patch is shown to you.

Another method is git show [SHA].

git log --stat: show diffstat of changes introduced at each commit.

It is also used to see the relative information of changes. --stat is simpler than the output of -p.

git add

Before committing, Git has a staging area (staging area), where newly added files can be placed or new changes can be added. The changes submitted when committing are the last changes added to the staging area, not the ones on our disk Change.

git add .

will recursively add all files in the current working directory.

git diff

git diff without parameters:

show diff of unstaged changes.

This command compares the difference between the current file in the working directory and the snapshot of the staging area. That is, the changes that have not been temporarily saved after modification.

To see the difference between the files that have been temporarily saved and the snapshot of the last submission, you can use:

git diff --cached command.

show diff of staged changes.

(Git 1.6.1 and later also allows the use of git diff --staged, the effect is Same).

git diff HEAD

show diff of all staged or unstated changes.

That is, compare the woking directory with the last commit All changes during the period.

If you want to see what has been changed since a certain version, you can use:

git diff [version tag]

Like the log command, diff can also be added with the --stat parameter to simplify the output.

git diff [branchA] [branchB] can be used to compare two branches.

It will actually return a patch from A to B, which is not the result we want.

Generally, the result we want is what are the changes after the two branches are separated, and what are the changes? Command:

git diff [branchA]...[branchB] is given.

Actually it is: git diff $(git merge-base [branchA] [branchB]) [branchB] The result.

git commit

Submit the changes that have been added.

git commit -m "the commit message"

git commit -a will first add the changes to all tracked files, and then Submit (a bit like a svn submission, no need to temporarily save it first). For files without track, you still need to git add.

git commit --amend to supplement the submission. The same parent as the current submission node will be used The node makes a new submission, and the old submission will be canceled.

git reset

undo changes and commits.

The HEAD keyword here refers to the latest commit at the end of the current branch. That is, the latest version on the branch in the repository.

git reset HEAD: unstage files from index and reset pointer to HEAD

This command is used to take out the files that were accidentally added from the staged state. It can be operated on a certain file alone: ??git reset HEAD - - filename, this - - can also be omitted.

git reset --soft

move HEAD to specific commit reference, index and staging are untouched.

git reset --hard

unstage files AND undo any changes in the working directory since last commit.

Use git reset --hard HEAD to reset, that is, after the last commit, all staged changes and changes in the working directory will disappear and be restored to the state of the last commit.

HEAD here can be written as SHA-1 of any commit.

Git reset without soft and hard parameters actually uses the default parameter mixed.

Summary:

git reset --mixed id changes the HEAD of git (that is, the commit record has changed), but the file has not changed (that is, the working tree has not changed) ). Cancel the contents of commit and add.

git reset --soft id. In fact, after git reset --mixed id, do git add again. That is, cancel the contents of commit.

git reset --hard id. Changes the git HEAD and the files.

Sort by change scope as follows:

soft (commit) < mixed ( commit add) < hard (commit add local working)

git revert

Reverse and undo the commit. Just change the wrong commit (commit ) name (reference) can be passed to the command as a parameter.

git revert HEAD: Undo the most recent submission.

git revert will create a new reverse submission, which can be passed Parameter -n to tell Git not to commit yet.

git rm

git rm file: Remove the file from the staging area and also move it Remove the working directory.

git rm --cached: Remove files from the staging area, but leave them in the working directory.

git rm --cached is functionally equivalent to git reset HEAD , clear the cache area, but leave the working directory tree unchanged.

git clean

git clean removes no track from the working directory File.

The usual parameter is git clean -df:

-d means to remove the directory at the same time, -f means force, because in the git configuration file, clean.requireForce=true , if -f is not added, clean will refuse to execute.

git mv

git rm - - cached orig; mv orig new; git add new

git stash

Push the current changes into a stack.

git stash will put the current changes into a stack. All changes in the directory and index (but not including untracked files) are pushed into a stack, leaving you with a clean working state, that is, at the last latest submission.

git stash list will display The list of this stack.

git stash apply: Take out the previous item in stash (stash@{0}) and apply it to the current working directory.

You can also specify other projects , such as git stash apply stash@{1}.

If you want to delete the item in stash while applying it, you can use git stash pop

to delete stash Projects in:

git stash drop: Delete the previous one, or you can specify parameters to delete a specified project.

git stash clear: Delete all projects.

git branch

git branch can be used to list branches, create branches and delete branches.

git branch -v can see the end of each branch One commit.

git branch: List all local branches, the current branch will be marked with an asterisk.

git branch (branchname): Create a new branch (when you use this When creating a branch, the branch is based on your last submission).

git branch -d (branchname): Delete a branch.

Delete remote branch:

git push (remote-name):(branch-name): delete a remote branch .

This is because the complete command form is:

git push remote-name local-branch:remote-branch

And the local-branch part here is empty, It means deleting remote-branch

git checkout

git checkout (branchname)

Switch to a branch.

git checkout -b (branchname): Create and switch to a new branch.

This command is the result of combining git branch newbranch and git checkout newbranch.

Checkout has another function: replacing local changes:

git checkout --

This command will replace the files in your working directory with the latest contents in HEAD. Changes and new files that have been added to the staging area will not be Will be affected.

Note: git checkout filename will delete all changes in the file that have not been temporarily saved and committed. This operation is irreversible.

git merge

Merge a branch into the current branch.

git merge [alias]/[branch]

Merge the remote branch into the current branch.

If a conflict occurs and needs to be modified manually, you can use git mergetool.

When resolving the conflict, you can use git diff. After the conflict is resolved, use git add to add it, which means The conflict has been resolved.

git tag

tag a point in history as import.

will be on a commit To create a permanent bookmark, you usually add a tag after releasing a release version or shipping something.

For example: git tag v1.0

git tag -a v1.0, -a The parameters will allow you to add some information, that is, make an annotated tag.

When you run the git tag -a command, Git will open an editor for you to enter the tag information.

We can use commit SHA to tag a past submission:

git tag -a v0.9 XXXX

When pushing, it is not If you want to include tags, you can add the --tags parameter when pushing.

When fetching, tags that can be reached by branch HEAD are automatically fetched, tags that aren't reachable from branch heads will be skipped. If you want to ensure that all tags are included, you need to add the --tags option.

git remote

list, add and delete remote repository aliases.

Because there is no need to use the complete URL every time, Git creates an alias for each remote repo URL, and then uses git remote to manage the list.

git remote: List remote aliases.

If you clone a project, Git will automatically add the original url, and the alias is called: origin.

git remote - v: You can see the actual url corresponding to each alias.

git remote add [alias] [url]: Add a new remote repo.

git remote rm [alias]: Delete one Existing remote alias.

git remote rename [old-alias] [new-alias]: Rename.

git remote set-url [alias] [url]: Update url. Yes Add the -push and fetch parameters to set different access addresses for the same alias.

git fetch

download new branches and data from a remote repository.

You can use git fetch [alias] to get a certain remote repo, or you can use git fetch --all to get all repo

fetch will get all the ones you don’t have locally Data, all removed branches can be called remote branches, they are the same as local branches (you can view diff, log, etc., and can also be merged to other branches), but Git does not allow you to checkout them.

git pull

fetch from a remote repo and try to merge into the current branch.

pull == fetch merge FETCH_HEAD

Git pull will first execute git fetch, then execute git merge, and merge the head of the fetched branch into the current branch. This merge operation will generate a new commit.

If you use the --rebase parameter, it Will execute git rebase to replace the original git merge.

git rebase

--rebase will not generate merged submissions. It will temporarily save all local submissions as patches and place them in the ".git/rebase" directory, and then update the current branch to the latest branch tip. Finally, apply the saved patch to the branch.

During the rebase process, conflicts may occur. Git will stop rebase and let you resolve the conflict. After resolving the conflict, use git add to update the content. Then there is no need to execute commit, just:

git rebase --continue will continue to make the remaining patches.

git rebase --abort will terminate rebase, and the current branch will return to rebase Previous state.

git push

push your new branches and data to a remote repository.

git push [ alias] [branch]

will merge the current branch to the [branch] branch on alias. If the branch already exists, it will be updated. If it does not exist, the branch will be added.

If multiple people push code to the same remote repo, Git will first run git log on the branch you are trying to push to check whether the current tip of the branch on the server can be seen in its history. If it cannot be seen in the local history If you go to the server's tip, it means that the local code is not the latest. Git will reject your push and let you fetch and merge first, and then push. This ensures that everyone's changes will be taken into account.

git reflog

Git reflog is a command to manage reflog. Reflog is a mechanism used by git to record reference changes, such as recording branch changes or Changes in HEAD references.

When git reflog does not specify a reference, the reflog of HEAD is listed by default.

HEAD@{0} represents the current value of HEAD, and HEAD@{3} represents The value of HEAD before three changes.

Git will record the changes in the reflog file corresponding to HEAD. The path is .git/logs/HEAD. The reflog files of the branches are placed in .git/logs/ In the subdirectories under the refs directory.

Special symbols:

^ represents the parent submission. When a submission has When there are multiple parent submissions, you can indicate the number of parent submissions by following ^: ^ is equivalent to ^1.

~ is equivalent to consecutive ^ .

git init

Create a new repo locally, enter a project directory, and execute git init. A repo will be initialized and created in the current folder. git folder.

git clone

Get the remote Git repo corresponding to a url and create a local copy.

The general format is git clone [url].

The cloned repo will be named after the last slash in the url. Create a folder. If you want to specify a specific name, you can git clone [url ] newname specified.

git status

Query the status of the repo.

git status -s: -s means short , the output mark of -s will have two columns, the first column is for the staging area, and the second column is for the working directory.

git log

Show commit history of a branch.

git log --oneline --number: Each log only displays one line, display number.

git log -- oneline --graph: can graphically display the branch merge history.

git log branchname can display the log of a specific branch.

git log --oneline branch1 ^branch2, you can view the branch 1, but not in branch 2. ^ means excluding this branch (you may need to add quotation marks to ^branch2 under Windows).

git log --decorate will display the tag information.

git log --author=[author name] You can specify the author's submission history.

git log --since --before --until --after Filter logs based on submission time.

--no-merges can exclude merge commits.

git log --grep Filter logs based on commit information: git log --grep=keywords

By default, git log - -grep --author is an OR relationship, that is, if one of them is met, it will be returned. If you want them to be an AND relationship, you can add the --all-match option.

git log -S: filter by introduced diff.

For example: git log -SmethodName (note that there is no equal sign between S and the following words).

git log -p: show patch introduced at each commit.

Each submission is a snapshot. Git will calculate the diff of each submission and display it to you as a patch.

Another method is git show [SHA ].

git log --stat: show diffstat of changes introduced at each commit.

It is also used to see the relative information of the changes. The output of --stat is simpler than -p Some.

git add

? ? ?在提交之前,Git有一個暫存區(qū)(staging area),可以放入新添加的文件或者加入新的改動. commit時提交的改動是上一次加入到staging area中的改動,而不是我們disk上的改動.

? ? ?git add?.

? ? ?會遞歸地添加當前工作目錄中的所有文件.

?

git diff

? ? ?不加參數(shù)的git diff:

? ? ?show diff of unstaged changes.

?????此命令比較的是工作目錄中當前文件和暫存區(qū)域快照之間的差異,也就是修改之后還沒有暫存起來的變化內(nèi)容.

?

?????若要看已經(jīng)暫存起來的文件和上次提交時的快照之間的差異,可以用:

?????git diff --cached 命令.

? ? ?show diff of staged changes.

?????(Git 1.6.1 及更高版本還允許使用 git diff --staged,效果是相同的).

?

? ? ?git diff HEAD

? ? ?show diff of all staged or unstated changes.

? ? ?也即比較woking directory和上次提交之間所有的改動.

?

? ? ?如果想看自從某個版本之后都改動了什么,可以用:

? ? ?git diff [version tag]

? ? ?跟log命令一樣,diff也可以加上--stat參數(shù)來簡化輸出.

?

? ? ?git diff [branchA] [branchB]可以用來比較兩個分支.

?????它實際上會返回一個由A到B的patch,不是我們想要的結(jié)果.

?????一般我們想要的結(jié)果是兩個分支分開以后各自的改動都是什么,是由命令:

? ? ?git diff [branchA]…[branchB]給出的.

? ? ?實際上它是:git diff $(git merge-base [branchA] [branchB]) [branchB]的結(jié)果.

?

?

git commit

Submit the changes that have been added.

git commit -m "the commit message"

git commit -a will first add the changes to all tracked files, and then Submit (a bit like a svn submission, no need to temporarily save it first). For files without track, you still need to git add.

git commit --amend to supplement the submission. The same parent as the current submission node will be used The node makes a new submission, and the old submission will be canceled.

git reset

undo changes and commits.

The HEAD keyword here refers to the latest commit at the end of the current branch. That is, the latest version on the branch in the repository.

git reset HEAD: unstage files from index and reset pointer to HEAD

This command is used to take out the files that were accidentally added from the staged state. It can be operated on a certain file alone: ??git reset HEAD - - filename, this - - can also be omitted.

git reset --soft

move HEAD to specific commit reference, index and staging are untouched.

git reset --hard

unstage files AND undo any changes in the working directory since last commit.

Use git reset --hard HEAD to reset, that is, after the last commit, all staged changes and changes in the working directory will disappear and be restored to the state of the last commit.

HEAD here can be written as SHA-1 of any commit.

Git reset without soft and hard parameters actually uses the default parameter mixed.

Summary:

git reset --mixed id changes the HEAD of git (that is, the commit record has changed), but the file has not changed (that is, the working tree has not changed) ). Cancel the contents of commit and add.

git reset --soft id. In fact, after git reset --mixed id, do git add again. That is, cancel the contents of commit.

git reset --hard id. Changes the git HEAD and the files.

Sort by change scope as follows:

soft (commit) < mixed ( commit add) < hard (commit add local working)

git revert

Reverse and undo the commit. Just change the wrong commit (commit ) name (reference) can be passed to the command as a parameter.

git revert HEAD: Undo the most recent submission.

git revert will create a new reverse submission, which can be passed Parameter -n to tell Git not to commit yet.

git rm

git rm file: Remove the file from the staging area and also move it Remove the working directory.

git rm --cached: Remove files from the staging area, but leave them in the working directory.

git rm --cached is functionally equivalent to git reset HEAD , clear the cache area, but leave the working directory tree unchanged.

git clean

git clean removes no track from the working directory File.

The usual parameter is git clean -df:

-d means to remove the directory at the same time, -f means force, because in the git configuration file, clean.requireForce=true , if -f is not added, clean will refuse to execute.

git mv

git rm - - cached orig; mv orig new; git add new

git stash

Push the current changes into a stack.

git stash will put the current changes into a stack. All changes in the directory and index (but not including untracked files) are pushed into a stack, leaving you with a clean working state, that is, at the last latest submission.

git stash list will display The list of this stack.

git stash apply: Take out the previous item in stash (stash@{0}) and apply it to the current working directory.

You can also specify other projects , such as git stash apply stash@{1}.

If you want to delete the item in stash while applying it, you can use git stash pop

to delete stash Projects in:

git stash drop: Delete the previous one, or you can specify parameters to delete a specified project.

git stash clear: Delete all projects.

git branch

git branch can be used to list branches, create branches and delete branches.

git branch -v can see the end of each branch One commit.

git branch: List all local branches, the current branch will be marked with an asterisk.

git branch (branchname): Create a new branch (when you use this When creating a branch, the branch is based on your last submission).

git branch -d (branchname): Delete a branch.

Delete remote branch:

git push (remote-name):(branch-name): delete a remote branch .

This is because the complete command form is:

git push remote-name local-branch:remote-branch

And the local-branch part here is empty, It means deleting remote-branch

git checkout

git checkout (branchname)

Switch to a branch.

git checkout -b (branchname): Create and switch to a new branch.

This command is the result of combining git branch newbranch and git checkout newbranch.

Checkout has another function: replacing local changes:

git checkout --

This command will replace the files in your working directory with the latest contents in HEAD. Changes and new files that have been added to the staging area will not be Will be affected.

Note: git checkout filename will delete all changes in the file that have not been temporarily saved and committed. This operation is irreversible.

git merge

Merge a branch into the current branch.

git merge [alias]/[branch]

Merge the remote branch into the current branch.

If a conflict occurs and needs to be modified manually, you can use git mergetool.

When resolving the conflict, you can use git diff. After the conflict is resolved, use git add to add it, which means The conflict has been resolved.

git tag

tag a point in history as import.

will be on a commit To create a permanent bookmark, you usually add a tag after releasing a release version or shipping something.

For example: git tag v1.0

git tag -a v1.0, -a The parameters will allow you to add some information, that is, make an annotated tag.

When you run the git tag -a command, Git will open an editor for you to enter the tag information.

We can use commit SHA to tag a past submission:

git tag -a v0.9 XXXX

When pushing, it is not If you want to include tags, you can add the --tags parameter when pushing.

When fetching, tags that can be reached by branch HEAD are automatically fetched, tags that aren't reachable from branch heads will be skipped. If you want to ensure that all tags are included, you need to add the --tags option.

git remote

list, add and delete remote repository aliases.

Because there is no need to use the complete URL every time, Git creates an alias for each remote repo URL, and then uses git remote to manage the list.

git remote: List remote aliases.

If you clone a project, Git will automatically add the original url, and the alias is called: origin.

git remote - v: You can see the actual url corresponding to each alias.

git remote add [alias] [url]: Add a new remote repo.

git remote rm [alias]: Delete one Existing remote alias.

git remote rename [old-alias] [new-alias]: Rename.

git remote set-url [alias] [url]: Update url. Yes Add the -push and fetch parameters to set different access addresses for the same alias.

git fetch

download new branches and data from a remote repository.

You can use git fetch [alias] to get a certain remote repo, or you can use git fetch --all to get all repo

fetch will get all the ones you don’t have locally Data, all removed branches can be called remote branches, they are the same as local branches (you can view diff, log, etc., and can also be merged to other branches), but Git does not allow you to checkout them.

git pull

fetch from a remote repo and try to merge into the current branch.

pull == fetch merge FETCH_HEAD

Git pull will first execute git fetch, then execute git merge, and merge the head of the fetched branch into the current branch. This merge operation will generate a new commit.

If you use the --rebase parameter, it Will execute git rebase to replace the original git merge.

git rebase

?????--rebase不會產(chǎn)生合并的提交,它會將本地的所有提交臨時保存為補丁(patch),放在”.git/rebase”目錄中,然后將當前分支更新到最新的分支尖端,最后把保存的補丁應(yīng)用到分支上.

? ? ?rebase的過程中,也許會出現(xiàn)沖突,Git會停止rebase并讓你解決沖突,在解決完沖突之后,用git add去更新這些內(nèi)容,然后無需執(zhí)行commit,只需要:

? ? ?git rebase --continue就會繼續(xù)打余下的補丁.

? ? ?git rebase --abort將會終止rebase,當前分支將會回到rebase之前的狀態(tài).

?

git push

? ? ?push your new branches and data to a remote repository.

? ? ?git push [alias] [branch]

? ? ?將會把當前分支merge到alias上的[branch]分支.如果分支已經(jīng)存在,將會更新,如果不存在,將會添加這個分支.

? ? ?如果有多個人向同一個remote repo push代碼, Git會首先在你試圖push的分支上運行g(shù)it log,檢查它的歷史中是否能看到server上的branch現(xiàn)在的tip,如果本地歷史中不能看到server的tip,說明本地的代碼不是最新的,Git會拒絕你的push,讓你先fetch,merge,之后再push,這樣就保證了所有人的改動都會被考慮進來.

?

git reflog

? ? ?git reflog是對reflog進行管理的命令,reflog是git用來記錄引用變化的一種機制,比如記錄分支的變化或者是HEAD引用的變化.

? ? ?當git reflog不指定引用的時候,默認列出HEAD的reflog.

? ? ?HEAD@{0}代表HEAD當前的值,HEAD@{3}代表HEAD在3次變化之前的值.

? ? ?git會將變化記錄到HEAD對應(yīng)的reflog文件中,其路徑為.git/logs/HEAD, 分支的reflog文件都放在.git/logs/refs目錄下的子目錄中.

?

?

特殊符號:

?????^代表父提交,當一個提交有多個父提交時,可以通過在^后面跟上一個數(shù)字,表示第幾個父提交: ^相當于^1.

?????~相當于連續(xù)的個^.

更多Git相關(guān)技術(shù)文章,請訪問Git使用教程欄目!

The above is the detailed content of Summary of common Git commands. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the .git directory, and what does it contain? What is the .git directory, and what does it contain? Jun 20, 2025 am 12:12 AM

The .git directory is the core of the Git repository and contains all the data required for version control. 1. It stores key contents such as objects (such as commits, trees, tags), references (such as branches and tag pointers), HEAD's current branch information, index temporary storage area, configuration files, etc. 2. Users usually do not need to manually operate these files, because direct editing may cause the repository to be damaged, such as deleting files, modifying references, or destroying indexes. 3. If there is a problem, you can use gitfsck or gitreflog to fix it. 4. Although .git content should not be changed at will, viewing files such as HEAD, config and logs can help understand the operation of Git. Understanding the structure of .git helps to gain a deep understanding of how Git works.

What is a three-way merge? What is a three-way merge? Jun 19, 2025 am 12:07 AM

A three-way merge is a merge method that uses the original version and two modified versions to resolve conflicts more accurately. 1. It is based on three versions: Common ancestor (base version), your changes (local version), and others' changes (remote version). 2. The system compares the two modified versions with the basic version, identify overlapping modifications and marks conflicting areas for manual processing. 3. Compared with two-way comparison, it can better understand the change context, reduce false positives and improve the security of automatic merging. 4. Commonly used in Git branch merge, PullRequest and advanced merge tools. 5. When using it, make sure that the selected basic version is the true common ancestor, and use tools that support three-way merging to ensure accuracy.

How do I clone an existing Git repository from a remote server? How do I clone an existing Git repository from a remote server? Jun 24, 2025 am 12:05 AM

TocloneaGitrepository,ensureGitisinstalledbycheckingwithgit--versionandinstallingifneeded.(1)Setupyourusernameandemailusinggitconfig.(2)UsegitclonefollowedbytherepositoryURLtocreatealocalcopy.(3)Forprivaterepos,useSSHwithanaddedkey.(4)Optionallyspeci

What is the purpose of the .gitignore file? What is the purpose of the .gitignore file? Jun 22, 2025 am 12:11 AM

.gitignore files are used to specify files or folders that Git should ignore, preventing them from being committed to the repository, thus avoiding unnecessary or sensitive files being traced. Its core functions include: 1. Exclude temporary files generated during development such as node_modules, .env, .log, etc.; 2. Avoid specific files generated by the operating system or editor entering version control; 3. Clean up the compiled products generated by the construction tool such as dist/, build/ directory; 4. Pay attention to syntax such as wildcard characters *, directories ending with /, and ! when setting. If you have submitted the file, you need to manually run gitrm-r--cached. Clear the cache and then resubmit it.

What are some common Git workflows (e.g., Gitflow, GitHub Flow)? What are some common Git workflows (e.g., Gitflow, GitHub Flow)? Jun 21, 2025 am 12:04 AM

Common Git workflows include Gitflow, GitHubFlow and GitLabFlow, each suitable for different development scenarios. Gitflow is suitable for projects with planned release, and is structured management through main, develop, feature, release and hotfix branches; GitHubFlow is centered on a single main branch, emphasizing continuous delivery, and is suitable for small teams or web applications that require frequent deployment; GitLabFlow increases environment awareness based on GitHubFlow, supports multi-environment deployment and uses tags to track production status. Each process has its own advantages and disadvantages, and should be adjusted according to the team size, project type and release frequency when choosing.

What are Git submodules, and why are they used? What are Git submodules, and why are they used? Jun 25, 2025 am 12:13 AM

Git submodule allows embedding of one Git repository as a subdirectory into another repository, suitable for references to external projects or components without merging their history. Reasons for using submodules include: managing third-party libraries with independent version control, maintaining independent development history for different parts of a project, and sharing code among multiple projects. The working principle of a submodule is: when adding a submodule, Git will record the specific submissions to be used, and the parent project only tracks the changes in the submodule, not the file changes in the submodule; the submodule needs to be initialized and updated after cloning the main repository; the submodule information is stored in the .gitmodules file and .git/config, and the actual file is located in the .git/modules/ path. Applicable scenarios include: Strict control of external dependency versions

How do I clear the entire stash list? How do I clear the entire stash list? Jul 01, 2025 am 12:02 AM

To clear the entire stash list in Git, there are no direct built-in commands, but it can be done in a few steps. First run gitstashlist to view all current stash entries, and then use gitstashdropstash@{n} to delete them one by one, or use gitreflogdelete --expire-unreachable=nowrefs/stash and gitgc-prune=now to force all stashes to be cleared at once. In addition, you can also use the bash loop command whilegitstashlist|grep-q'^stash@';dogitstashdrop;d

What is the difference between git fetch and git pull? What is the difference between git fetch and git pull? Jun 17, 2025 am 09:19 AM

The main difference between Gitfetch and Gitpull is that gitfetch only gets changes from remote repositories and does not merge, gitpull gets and automatically merges changes to the current branch. Specifically: 1. gitfetch is used to download remote updates, but does not modify local files or branches, and is suitable for review before applying changes; 2. gitpull is equivalent to executing gitfetch first and then executing gitmerge, which is suitable for scenarios where new changes are trusted and hope for quick updates; 3. gitfetch should be used when it is necessary to control the timing of merges or troubleshoot problems, and gitpull is more suitable for automated processes or stable branches to quickly update.

See all articles