finish commit.md and add social banners

This commit is contained in:
Ric Harvey 2024-05-03 10:56:11 +01:00
parent 5c82b6096b
commit fd4c929bb5
Signed by: ric
GPG key ID: 7FDEB4C0C7D5CB61
6 changed files with 123 additions and 12 deletions

View file

@ -408,4 +408,4 @@ Now you're all ready to get started with learning how to use Git.
---
##### Follow me for more guides
[<img src="./img/mastodon.png" width="8%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="5%">](https://www.linkedin.com/in/richarvey/)
[<img src="./img/mastodon.png" width="6%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)

View file

@ -0,0 +1,8 @@
## Branches
---
##### Follow me for more guides
[<img src="./img/mastodon.png" width="6%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)

View file

@ -53,4 +53,4 @@ git rebase --interactive HEAD~3
---
##### Follow me for more guides
[<img src="./img/mastodon.png" width="8%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="5%">](https://www.linkedin.com/in/richarvey/)
[<img src="./img/mastodon.png" width="6%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)

109
commit.md
View file

@ -1,27 +1,116 @@
## Working with commits
## Adding files
When working with commits, utilize git commit -m to record changes, git amend to modify the most recent commit, and try your best to adhere to commit message conventions.
Before you can commit your work to local or remote repositories you need to make sure git is tracking the file you have changed, otherwise those changes won't sync. To add a specific file to the git repository run the command:
```bash
# Change <filename> for the file you want to add
git add <filename>
```
Now when you do a commit this file will be tracked and if you make changes to it in the future that will be tracked also. You only need to add the file once.
Now heres a short cut for you, if you want to add all the files in a directory you can run the following to save you a lot of time.
```bash
# Add all files in the git repo
git add .
```
> It is possible to have files in your working directory that are not tracked and pushed to the local and remote repositories.
### Excluding files
There are times when you want to exclude certain files from your git repository. These could be credential files or something more harmless like ```_DS_Store``` folders that get created when you look at images. A ```.gitignore``` file specifies intentionally untracked files that Git should ignore, and thus keeps those files from being commited even when you run ```git add .```. To create this file:
- Make sure you are in the root of your git repository
- create a new file called ```.gitignore```
- add the rules for the files to ignore
```
# Make sure to add a message to each commit
# OSx image cache
.DS_Store
# Some Java files you might want to ignore
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
```
- Now make sure to add the ```.gitignore``` file to git itself:
```bash
git add .gitignore
git commit -a
```
- If you want to ignore files that you've already added to the repo you need to run the following command:
```bash
git rm --cached <filename>
```
## Commits
When working with commits it's good practice to add a commit message that describes the changes you've made. This is also why it's good to make frequent commits and split your work into smaller units of work, meaning the commit message is simpler to create and more accurate. There are a coupole of ways you can add the commit message from the command line, the first isthe way I tend to use because you get to see a nice easy to read list of things that have changed and maybe files you've forgot to include. It opens up your default text editor for you to write the commit message in, yet again in my case this is vim. If you are wondering how to exit vim it's ``ESC`` then ``:wq``. This commit in this way do the following:
```bash
git commit -a
# Now enter you commit message at the top of the file and save and exit
```
However, some people prefer to add their commit message on the command line for speed and convenience. You can do this by adding the ```-m``` flag:
```
# Add a message on the command line
git commit -m "meaningful message"
```
If you have changes to your last commit, you dont have to create another commit altogether, you can use the - — amend flag to amend the most recent commit with your staged changes
If you realise you've made a mistake and want to change the last commit, you don't have to create a new commit, you can use the ```-—amend``` flag to amend the most recent commit
```
# make your changes
git add .
git commit --amend
# This will open your default text editor to modify the commit message if needed.
git push origin your_branch --force
```
> Exercise caution when utilizing --force, as it has the potential to overwrite the history of the target branch. Its application on the main/master branch should be generally avoided.
> When you push changes you may need to use the ```-force``` flag but this can be dangerous so use cautiously.
As a rule of thumb its better to commit more often than not, to avoid losing progress or accidentally resetting the unstaged changes. One can rewrite the history afterwards by squashing multiple commits or doing an interactive rebase.
As a rule of thumb its good practice to commit frequently, thus avoiding loss of progress or accidentally resetting the unstaged changes.
Use git log to show a chronological list of commits, starting from the most recent commit and working backward in time
### Sync Commits to the Remote Repository
### Sync Commits
Right so you're commited this is good. If you remember back to our diagram about the stages of a git repository you've now moved the files into the local repository. It's now time to sync them back up to the remote repository. Now this is pretty simple just run the following command:
```bash
git push
```
If you have no merge conflicts all will be good and the code will now appear in the remote repository on the branch you are working on.
> If you do have a **merge conflict** we'll deal with this in the [merging](./merging.md) file.
---
##### Follow me for more guides
[<img src="./img/mastodon.png" width="6%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)

View file

@ -0,0 +1,8 @@
## Setting up a new repository
## Cloning an existing repository
---
##### Follow me for more guides
[<img src="./img/mastodon.png" width="6%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)

View file

@ -0,0 +1,6 @@
## Merging
---
##### Follow me for more guides
[<img src="./img/mastodon.png" width="6%">](https://awscommunity.social/@Ric)[<img src="./img/linkedin.png" width="4%">](https://www.linkedin.com/in/richarvey/)