The second Git my notes - File Management

table of Contents

Adding 2.1 and submit documents

2.2 File Deletion

2.3 File Rename

2.4 ignore the specified format file

2.5 undo changes

2.6 diff

2.7 Compression warehouse


Adding 2.1 and submit documents

Add file

Add a file: git add file.c

Add all of the files: git add.

effect:

    1) has been tracking files: save changes from the work area to the staging area

    2) untracked files: Add git tracking range

Submission

The entire contents of the staging area committed to the repository

- Single-step submission: git commit -m "commit info"

- a one-time submission: git commit -a

- Modify the last commit: git commit --amend # The submission will create a new commit object, replace the previous commit object

Note: If you do not save modifications to the staging area, is not submitted to the repository.

 

2.2 File Deletion

1) is removed from the working directory, and the staging area

method one:

    First removed from the working directory, use rm -rf file.c

    Then use git add file.c

    Finally, commit git commit -m "delete file.c"

Second way:

    The first to use git rm -f file.c

    And then commit git commit -m "delete file.c"

Avoid file appears in the list of untracked

After you remove and submit the file is no longer being tracked repository, but the repository there is still a snapshot of the files

2) removed from the staging area, the working directory reserved

Use the command: git rm --cached file.c

They include: library files, executable files, logs, temporary files

3) removed from the repository: Version back to a previous version of the dates

Revocation submitted to the staging area: git reset --soft SHA-1 (for example to fall back on a version of the SHA-1 = HEAD ^)

Revocation submitted to the workspace: git reset --mixed SHA-1

The restoration work area, staging area and the repository to the specified version ( not recommended ): git reset --hard SHA-1

Note: Delete is also considered to be modified, you can restore from the repository.

 

2.3 File Rename

Rename the file: git mv old_file new_file, and then submit

Rename practice

File move: mv old_file new_file

Delete old files: git rm old_file

Add a new file: git add new_file

 

2.4 ignore the specified format file

Some files do not have to be submitted to the repository

- executable files, log files, temporary files, libraries,

Ignore file mode: glob pattern matching

- Ignore the line starting with #

- Ignore the end of a format file: * [ao].

- except for a library file, do not ignore:! clib.a

- ignore temporary files: * ~

- ignore a file in the root directory: / text

- Ignore all the files under a directory: libs /, libs / * a.

Manually create .gitignore file

 

2.5 undo changes

Undo workspace submitted

git checkout file.c

Return to let the state's most recent commit or add

If the file is not added to the staging area: after revocation and repository as

If the file has been added to the staging area and has been modified: Back to the staging area status

Revocation of the contents of the staging area

git reset HEAD file.c

The revocation modify staging area off back into the work area

Submit revocation repository

git reset --hard SHA-1(HEAD^)

Fallback version, and refresh the workspace, completely discard the contents of previously modified

Previously submitted repository objects still exist alone (the repository can be compressed, releasing space)

 

2.6 diff

Compare the work area and staging area difference

What are the new changes git diff # view the file has not yet been staging

Compare staging area and repository difference

git diff --cached [HEAD]

git diff --staged SHA-1

View the temporary differences between files and snapshots of the last commit

Comparison of workspace and repository difference

git diff HEAD (SHA-1) # View has not been staging files and documents submitted by the difference between the latest snapshot

Compare the differences between the two versions

The difference between the different versions of git diff to see a version of another version of the SHA-1 SHA-1 #

 

2.7 Compression warehouse

Compression repository

In daily operation, git snapshots take up disk space

git modified delta stored in the storage unit

By git gc compact delta storage unit command, save disk space

Snapshot storage

For the modified content: do snapshot processing and preservation

For unmodified files: make reference treatment

View git up disk space: du -sh

Released three original articles · won praise 0 · Views 76

Guess you like

Origin blog.csdn.net/qq_33669963/article/details/104107246