rm -rf merge-conflict-example
git clone https://github.com/jameshowison/merge-conflict-example.git
cd merge-conflict-example
git log -1 --skip 1 --remerge-diff
## Cloning into 'merge-conflict-example'...
## commit 50911dc2232965238790ad8ca3fdcabe56b41639
## Merge: 57c1c6c 99b328f
## Author: pablo-carbajo1 <99198265+pablo-carbajo1@users.noreply.github.com>
## Date: Thu Mar 2 18:06:57 2023 -0600
##
## Merge branch 'main' into patch-1
##
## diff --git a/animals.txt b/animals.txt
## remerge CONFLICT (content): Merge conflict in animals.txt
## index f9970b6..f07b36e 100644
## --- a/animals.txt
## +++ b/animals.txt
## @@ -1,8 +1,5 @@
## -<<<<<<< 57c1c6c (Update animals.txt)
## lion Contributor B
## -=======
## lion contributor A
## ->>>>>>> 99b328f (Merge pull request #4 from lisahyuniko/patch-1)
## tiger
## leopard
## turtle
Appendix A — Skills faq
A.1 git issues
A.1.1 Set my name and email
git wants to add your name and email to commits. These are distinct from your github
account (remember git
can be used independently of an online service or with online services other than github).
If you are seeing messages that end like this:
You can suppress this message by setting them explicitly. Run the
following command and follow the instructions in your editor to edit
your configuration file:
git config --global --edit
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
Then you can run these commands to set a username and email. Note that these can be anything, they aren’t a login or checked against anything, they are just metadata attached to your commits. Nonetheless having them make sense for your identity makes sense when sharing code publically. They can easily be a made up identifier (pseudonym/handle/accountname).
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
A.1.2 Password pop-up repeats too often
The username/password pop-up can come up too often. Especially with GitHub requiring a PAT (and not the same password used on the website) this can be a hassle, since the PAT is not configurable and has to be copy/pasted.
Rstudio is generating that pop-up, but the frequency is controlled by a gitconfig variable. The default without configuration is 15m so if we don’t run a git command for 15m it expires the cache and pops up again. We can make it show up less with:
git config --global credential.helper 'cache --timeout=10000000'
That means that the cache won’t expire for 10,000,000 seconds (which is 16 weeks).
Thanks to https://happygitwithr.com/https-pat.html#store-credentials-through-organic-git-use and the Rstudio community forums for helping me with that https://community.rstudio.com/t/git-user-pass-pop-ups-when-using-git-in-terminal-window/161213
A.1.3 git commit throws me into a weird mode
If you type git commit
just on its own rather than git commit -m "Some message"
you will see something like this:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Your branch is up to date with 'origin/master'.
git needs a commit message. When you don’t provide one it throws you into a text editor, expecting you to type a small novel.
The editor that you go into by default is the vi
or vim
editor. It can be confusing because it has multiple modes (ie typing doesn’t always just produce text).
The best option is to:
- Hit
esc
twice: Esc Esc
- Type
:q!
and hit Enter - Redo your commit using `git commit -m “Some message”
See https://stackoverflow.com/questions/11828270/how-do-i-exit-vim
The option below does not work in Rstudio because Rstudio captures the
You can also configure git to use another editor: https://stackoverflow.com/questions/2596805/how-do-i-make-git-use-the-editor-of-my-choice-for-editing-commit-messages
For example, the nano
editor is easier to use. You can set that run running
git config --global core.editor "nano"
In nano
we can type a commit message as usual. The bottom of the screen shows commands. Nano uses the ^
symbol to represent the
Ctrl + O
Then:
Ctrl + X
A.2 I accidentally made my home folder a git repo
If you are in your home folder but git status
doesn’t give a “fatal error” then you’ve accidentially made your home folder into a git repository (probably by running git init
in that folder).
In this case we need to undo this. We can’t delete our home folder, because it has everything else inside it. We have to somehow tell the computer that the home folder should not be a git repo. Happily, then only thing that makes it a git repo is that it has a .git
folder inside it. You can confirm by running:
ls -lah
The -a
flag to ls
makes it show all files and folders, even the hidden ones that start with a dot.
To fix this we could just delete the .git
folder but we might lose data that way (if we had already added work to that repo). So safest thing is to make a new folder inside our home folder, and then move the .git
there.
mkdir backup_home_git
mv ./.git ./backup_home_git
Now you could cd backup_home_git
and use that folder as a git repo. But probably you are about to clone from github (in which case a new folder will be created) or you are about to use git init
to create a new local repo (in which case you should create a folder first, cd
into it, then run git init
.
A.3 Vizualizing git trees (aka gitviz)
In this course we are using a command that I usually call “gitviz” for short:
git log --oneline --abbrev-commit --all --graph --decorate --color
This produces reasonably readable graphs (especially for the teaching repos used in this course).
They look like this:
jlh5498@educcomp04:~/github_repos/i320_test3,,\n git log --oneline --abbrev-commit --all --graph --decorate --color
* d8ab2c1 (HEAD -> main, origin/main, origin/HEAD) Merge pull request #1 from jameshowison/new-feature
|\
| * ffb601d (origin/new-feature, new-feature) added extra
|/
* f256ee7 Added line to README
* 093fb0c Initial commit
Or as an image (with coloring as on Edupod Rstudio):
You can read a little more about how to read these graphs here https://stackoverflow.com/questions/22313343/git-graph-what-do-the-lines-and-asteriks-denote
Long story short:
- The asterisk characters (
*
) show a single commit - The lines formed with characters like (
| \ /
) help us follow which branches a commit was on. - The words in parens show branch names, and can include the names of remotes (e.g.,
origin/new-feature
means thenew-feature
branch on theorigin
remote)
It is a long command, so you can either keep it handy in a pastebin (I use Typinator) or you can register it as a command alias for git itself:
git config --global alias.viz 'log --oneline --abbrev-commit --all --graph --decorate --color'
So then you can just type:
git viz
A.4 Seeing a merge conflict using git log
In one assignment students have to submit a repo showing a resolved merge conflict when accepting a PR. This raised the question of whether I could see this looking at the repo. Student questions helped me figure that our, leading me to https://stackoverflow.com/questions/15277708/how-do-you-see-show-a-git-merge-conflict-resolution-that-was-done-given-a-mer which highlighted this as an issue in presenting merge conflicts for review. The most recent answer, led me to discover a new feature in git
git log --remerge-diff
This enables one to see the files with the <<<<<<
type conflict markers shown.
B How to add an image using quarto on edupod
Quarto is like html in that the main .qmd
document references separate image files, rather than incorporates them inside the main file itself. You have to place the images separetely (and also git add
the image files separately).
On Edupod getting figures into your quarto document takes two steps:
- Upload the file to the server
- Use the Visual mode in the quarto file editor to insert the picture.
Using the Render button will confirm that your images are found.
Then don’t forget to git add
the image files as well. Run a git status
to check which files are included.