DEVOPS DAY 3
> What we'll cover?
Compare and verify Git changes
Rename and Move file in Git
Find commit or File History
Exclude unwanted files in Git
Delete file/files in Git
Git stash
Git Alias
Git Complete Workflow
Q&A
> Compare and verify Git changes
git diff
This command is used to compare the files between working directory and staging area.
git diff <file_name>
To compare the given file between working directory and staging area.
> Rename and Moving files in Git
Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn’t see that a file was moved; it sees that there’s a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).
git mv :
This command is used to move the file to a new one.
> File Commit History
Already learn about “git log” cmd.
git log :
This command is used to get the last 10 commit details.
gitk <file_name> :
To get a graphical view.
--follow:
To follow file even after renaming.
git log –follow <file_name>
OR
gitk –follow <file_name>
> Exclude unwanted files
Locally:
Go to .git/info and open exclude file.
Add entry to exclude files / folders.
Changes to this file will only be available to local repository.
It is not sharable to whole team.
Globally:
Manually create a file called “.gitignore” in the working directory.
Inside this file add entry or pattern to exclude the files / folders.
We can share this file by committing it to the central repository of the project.
> Delete / Remove File
The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory. There is no option to remove a file from only the working directory.
To remove a file:
git rm <file_name>
To remove files recursively / To remove a folder:
git rm –r <folder_name>
To delete file only from Staging Index:
git rm –cached <file_name>
> Git Stash
The git stash command takes your uncommitted changes (both staged and un-staged), saves them away for later use, and then reverts them from your working copy.
At this point you're free to make changes, create new commits, switch branches, and perform any other Git operations; then come back and re-apply your stash when you're ready.
git stash
Save stashes with a description
git stash save "message“
> To add untracked files in stash
git stash -u
Note : stash is local to your Git repository; stashes are not transferred to the central repository server when we push.
> Re-applying your stashed changes
We can reapply previously stashed changes with git stash pop:
git stash pop
Popping your stash removes the changes from your stash and reapplies them to your working copy.
> Git Stash List
A Developer can run git stash several times to create multiple stashes, and then use git stash list to view them. By default, stashes are identified simply as a "WIP" – work in progress – on top of the branch and commit that you created the stash from.
git stash list
> To clean Stash
delete all stashes:
git stash clean
Delete a particular stash:
git stash drop <stash>
> Git Alias
The term alias is synonymous with a shortcut. Alias creation is a common pattern found in other popular utilities like `bash` shell. Aliases are used to create shorter commands that map to longer commands. Aliases enable more efficient workflows by requiring fewer keystrokes to execute a command.
git config --global alias.co checkout
Aliases were created with the --global flag which means they will be stored in Git's global operating system level configuration file. The global config file is located in the User home directory at /.gitconfig
Comments
Post a Comment