diff
is used to find differences between two files. For easier usage, combine it with -u
:
diff -u file1 file2
Compares two files line by line, displaying the differences side by side:
diff -u original.txt updated.txt
patch
applies file differences to another file. Example:
- Save differences as a
.diff
file:diff -u original.txt updated.txt > changes.diff
- Apply the patch:
patch original.txt changes.diff
git config --global user.name "Your Name"
git config --global user.email "[email protected]"
git config -l # Check current configuration
Enable GPG signing for commits to enhance security:
- Generate a GPG key:
gpg --full-generate-key
- Add your GPG key to Git:
gpg --list-secret-keys --keyid-format=long git config --global user.signingkey <key_id> git config --global commit.gpgsign true
- Export your GPG key for public sharing:
gpg --armor --export <key_id>
- Verify GPG signing with:
git commit -S -m "Your message"
git init # Initialize a new repository
git add file.txt # Add a file to the staging area
git rm file.txt # Remove a file from the repository
git commit # Commit changes (opens a text editor for the message)
git commit -m "Your commit message" # Commit with a message inline
git commit -a # Stage tracked changes and commit them in one step
git commit --amend # Modify the last commit
git status # Show the status of the working directory
git log # View commit history
git log -p # Show commits with changes (patch format)
git log --graph --oneline --all # View commit tree in one line
git log --stat # Display added/deleted statistics per file
git diff <branch1> <branch2> # Compare two branches
git diff <branch>:<file> # Compare a file from another branch
git diff # Show differences between working directory and index
git diff --staged # Show differences between staged files and last commit
git add -p # Interactively choose changes to stage
git reset HEAD <file> # Unstage a file
git reset -p # Interactively reset changes
git revert <commit_id> # Create a new commit to undo a previous one
git commit --amend # Amend the last commit
git clone <URL> # Clone a remote repository
git pull # Fetch and merge changes from the remote repository
git push # Push commits to the remote repository
git remote -v # View configured remotes
git remote show origin # View details of a remote repository
git branch # List branches
git branch <name> # Create a new branch
git branch -d <name> # Delete a branch
git branch -D <name> # Force delete a branch
git checkout <branch> # Switch to a branch
git checkout -b <branch> # Create and switch to a new branch
git merge <branch> # Merge a branch into the current branch
git merge --abort # Abort a merge in case of conflicts
git log --graph --oneline # View branch commit history in graph form
git branch -r # List remote branches
git mv <old-name> <new-name> # Rename or move a file
git fetch # Download changes from the remote repository
git commit -a -m "Message" # Stage and commit in one step