Git repository is a version-controlled storage space for your project's files,
which allows you to track changes, collaborate with others, and maintain a history of modifications.
Here are key points:
Types:
- Local Repository: On your computer.
- Remote Repository: Hosted on a server (e.g., GitHub, GitLab).
Key Concepts:
- Commit: A snapshot of changes.
- Branch: A parallel version of the repository.
- Merge: Combining changes from different branches.
- Clone: Copying a remote repository to your local machine.
- Pull: Fetching and integrating changes from a remote repository.
- Push: Sending local changes to a remote repository.
Testing perspective
How to pull the full code from a remote repository (server)
git clone [repository-url]
Ex : git clone https://github.com/ROCm/DeepLearningModels
Difference between git clone & git pull
git clone
- Purpose: Creates a copy of a remote repository on your local machine.
- Use Case: When you want to start working on a project that you haven't downloaded yet.
- Functionality: Downloads the entire repository, including its history, branches, and files.
git pull
- Purpose: Updates your local repository with changes from a remote repository.
- Use Case: When you already have a local repository and want to sync it with the latest changes from the remote.
- Functionality: Fetches changes and merges them into your current branch.
- 1st way:
- cd local_repository
- git pull -------------> sync it with the latest changes from the remote.
- 2nd way:
- cd local_repository
- git pull origin [branch-name] -----> used to update your local repository with changes from a specific branch of a remote repository
Example
If you’re currently on the
main
branch and you want to pull the latest changes from thedevelop
branch on the remote repository, you would rungit pull origin develop
Summary
- Clone: Use for initial setup of a project.
- Pull: Use to update an existing local repository with new changes.
How to check previous git commit changes?
cd repository_name
git log (type this command in the git bash prompt, and it will display as below )
commit id (HEAD -> Branch_name)
Author: Narendra <EMPID@companyname>
Date: Fri Sep 17 11:38:40 2021 +0530
latest changes in input file & added chamber details in file_name.py
Press the down arrow mark (arrow mark ) then you can see all previous commit changes datewise
Press q for quit from the git log
While testing if you want to test a particular commit then follow the below process
1. git log --> This will display all commits
Use the up arrow or down arrow buttons to see list of all commits (identify on which commit you want to perform the test)
2. git reset --hard commit_id Example: git reset --hard 15cde7c
Difference between git log and git log --oneline
git log
Output: Displays detailed commit information for each commit, including:
- Commit hash (SHA-1)
- Author name
- Author date
- Commit message
- Any parent commits
Use Case: Useful when you need in-depth information about each commit, including the complete commit messages and metadata.
git log --oneline
Output: Provides a simplified view of the commit history, showing:
A shortened commit hash (first 7 characters)
The commit message
Use Case: Great for getting a quick overview of the commit history without all the details. It’s useful for seeing a summary of changes and navigating through commits quickly.
Development perspective
git steps:
git pull --rebase # to pull the latest code from git
git pull --rebase # again doing the same .. just for conformation [optional]
Already up to date.
git status
git add <1st file name along with path>
git add <2nd file name along with path>
git add <3rd file name along with path>
# or you can add all files at once by using git add . command
git status
git commit -m " you can provide the message "
git push origin HEAD:refs/for/project-int
open git link then add reviewers (who can review your code)
==============================================================
How do you enter into a particular branch & test? how do you come out of that branch again?
git branch (cmd will be used to check your current branch=> note down somewhere Ex: * master)
git checkout <brach_name_need_to_test>
git branch ==> cmd will be used to check your current branch, have you moved or not?
Do your testing
git checkout <master>
git branch
==============================================================
==============================================================
In the latest git code, if you modify code in a single file or multiple files when you have given git status, it will display that file change.
if you don't want that file changed then
git restore <filename along with path>
git status
==============================================================
When you have committed and pushed your code to git, but you don't want to do that then you have to follow the below procedure
git log (type this command in the git bash prompt, and it will display as below )
commit id (HEAD -> Branch_name)
Author: Narendra <EMPID@companyname>
Date: Fri Sep 17 11:38:40 2021 +0530
latest changes in input file & added chamber details in file_name.py
Press q for quit from the log
git reset --hard origin/<branch>
git pull origin fusion-int --rebase
git status
after this, you can pull the latest code if you want by typing the below command.
git pull --rebase
==============================================================
==============================================================
==============================================================
Request: If you find this information useful, please provide your valuable comments.