From fd4c929bb5945ce7cd36ca374ef526296b52af86 Mon Sep 17 00:00:00 2001 From: Ric Harvey Date: Fri, 3 May 2024 10:56:11 +0100 Subject: [PATCH] finish commit.md and add social banners --- README.md | 2 +- branches.md | 8 ++++ cheat-sheet.md | 2 +- commit.md | 109 +++++++++++++++++++++++++++++++++++++++++++----- getting-code.md | 8 ++++ merging.md | 6 +++ 6 files changed, 123 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 60eedb9..b9505c1 100644 --- a/README.md +++ b/README.md @@ -408,4 +408,4 @@ Now you're all ready to get started with learning how to use Git. --- ##### Follow me for more guides -[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file +[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file diff --git a/branches.md b/branches.md index e69de29..3bb2f23 100644 --- a/branches.md +++ b/branches.md @@ -0,0 +1,8 @@ +## Branches + + + +--- +##### Follow me for more guides + +[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file diff --git a/cheat-sheet.md b/cheat-sheet.md index 7ee8954..720b79b 100644 --- a/cheat-sheet.md +++ b/cheat-sheet.md @@ -53,4 +53,4 @@ git rebase --interactive HEAD~3 --- ##### Follow me for more guides -[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file +[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file diff --git a/commit.md b/commit.md index 5e67f1c..a87da1f 100644 --- a/commit.md +++ b/commit.md @@ -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 for the file you want to add +git add +``` + +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 +``` + + +## 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 don’t 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 it’s 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 it’s 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 + +[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file diff --git a/getting-code.md b/getting-code.md index e69de29..230e456 100644 --- a/getting-code.md +++ b/getting-code.md @@ -0,0 +1,8 @@ +## Setting up a new repository + +## Cloning an existing repository + +--- +##### Follow me for more guides + +[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file diff --git a/merging.md b/merging.md index e69de29..88621c2 100644 --- a/merging.md +++ b/merging.md @@ -0,0 +1,6 @@ +## Merging + +--- +##### Follow me for more guides + +[](https://awscommunity.social/@Ric)[](https://www.linkedin.com/in/richarvey/) \ No newline at end of file