workshop
(tentative) Name the most important thing you learned yesterday
git commit -p
:+1:--staged
flag to git diff
. :+1:git commit -p
. Also the difference between checkout
and reset
git commit -p
and git diff --staged
. Excellent pedagogically organized materialHEAD
was mentioned briefly at the end (the casette tape analogy) but indeed this question perhaps arrives too early. I am noting these good points as issues so that we follow up: https://github.com/coderefinery/git-intro/issues/267 and https://github.com/coderefinery/git-intro/issues/268https://coderefinery.github.io/git-intro/06-branches/
--orphan
branches, where the first commit of the branch has no parent: git branch --orphan somename
--allow-unrelated-histories
option (https://git-scm.com/docs/git-merge#Documentation/git-merge.txt—allow-unrelated-histories)mkdir recipe
cd recipe
git init
git add
both files, then git commit
HEAD
is our current position, in analogy of the recorder head for those who remember casette tapes. when we switch branches with git checkout somebranch
or git switch somebranch
, then HEAD
moves over to that place.HEAD
typically points to a branch (and a branch is like a sticky note pointing to a commit hash). But HEAD
can also point directly to a commit hash and in the latter case we have a “detached HEAD” state.What to do
Solution of the above ex:
git config --global alias.graph "log --all --graph --decorate --oneline"
git status
git branch experiment master
git checkout experiment
git branch
https://coderefinery.github.io/git-intro/06-branches/#exercise-create-and-commit-to-branches
git graph
alias is defined and worksYour git graph
should produce a graph similar to the picture in this exercise
experiment
after committing changes to less-salt
?
git graph
alias should show the whole tree. If the tree is big you can scroll it with arrow keys, q
returns to your command line.git graph
, but gitk allows to visualize longer trees in a GUI so I was wondering if there is patch to visalize it with all branches and not only the current one. git graph is awesome, but having a GUI is also good sometimesgit branch new-branch 2e70ce4
)?
git branch -d
or git branch --delete
if the commits have not been merged to another branch.git branch -D
Merging branches on your own until: XX:22
git remote...
and push
and then delete the branch?
git remote add origin someurl; git push origin thatonebranch
. Then you have a new repo and only that branch in there with all commits on that branch. And after that, indeed you can delete the branch on that original repository.
cutaway-feature-branch
to master
of the remote. Then you can clone the new repo anew and delete the cutaway branch in the original repo. This can get messy, since we’re used to have only one remote, and remote branches to be named exactly as they are locally.
cp -r
the repository folder to a new folder and you delete the branch in one and delete all other branches in the other.diff
does not work, in the context of merging commits? Will it just check the checksum and report a conflict if the files are different? Or are there some useful tools for non-text files?
like-cilantro
and master
in two different ways before that merge. only after we have merged like-cilantro
we have a modification of that line on master
and the second merge will conflict. Please let me know if this explanation was not helpful enough and we expand.like-cilantro
version over the master
version?
less-salt
and experiment
are topologically not ordered but happened “in parallel”. In this case Git does not take the later change in terms of time stamp but it compares whether they are related in terms of “ancestry”. Please do not hesitate to raise this issue if it is not clear or not well explained.Create two branches as the instructor showed
Ask for help if you need it on the chat or here
error: Merging is not possible because you have unmerged files.hint: Fix them up in the work tree, and then use 'git add/rm <file>'hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.
git add somefiles
. In other words we signal conflict resolution by staging the change. From the error I guess the staging did not happen?
git reset --hard
don’t we lose the changes introduced in the commit?
reset
: git reset --hard
moves the branch to a commit in the past. But the commits are still there and they are now reachable via the newly created branch.git reset --hard somehash
before “saving” the commits to a new branch, I will have a hard time finding these commits again. In fact they have not been deleted and I can recover them with the help of git reflog
which keeps a log of all commits you have visited, for some time.git add
. You can then type git commit
and you will have a pre-filled commit messagehttps://coderefinery.github.io/git-intro/09-remotes/
main
instead of master
for the name of the master branch. It is possible to change it in the personal settings of your account in the “Repositories” tab, and restore the default to master for new repositories.
master
but now GitHub defaults to main
.git remote -v
initially would be good idea before adding the remote link
fatal: remote origin already exists.
git remote add ...
with a remote already defined. You can remove the remote with git remote rm origin
and then try again and it will work. origin
is a placeholder and we will explain tomorrow what this really means. :ok_hand:myusername@users.noreply.github.com
(replace myusername
with your github username). This way, nobody can write you to that address but GitHub will still be able to count your contributions.
git log
so if you don’t want your email address to become visible at any point for nobody, you can use the above answer.
git config --global user.email=gitusername@users.noreply.github.com
(replace “gitusername”)git remote -v
git remote rm origin
(this removes the “origin” placeholder)git remote -v
git remote add origin ...
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
What is most likely wrong?
func
in master
that is used in branch a
but altered in branch b
, these three branches can be merged without conflict but it will cause erroneous behavior, won’t it? Because the usage of func
in branch a
differs from its implementation in branch b
(and hence in the merged master
branch).
https://coderefinery.github.io/git-intro/10-archaeology/
master
to main
with git branch -M main
. We have done that because recenly GitHub started calling the default branch “main”. This setting can be changed. It’s also good to see that there is nothing really special about “master” or “main”, they are just names and can be renamed.
git log -S
look? Only in the commit Messages?
git log
or git log --oneline
mostly depends on your preference I guess, but Gitbash is probably somewhat easier for Git and has unix commands
git graph
for example will become huge pretty large. Love VisualStudio code with a linux shell.
note: git checkout -b new_branch master
is just a shorthand to git branch new_branch master
and git checkout new_branch
. So nothing really new, but I believe we have not seen it before
git annotate
is extremely usefulgit grep
gave no output at all?
git grep somepattern
(where somepattern is the text you search for)
C:\Users\XXXX\recipe\recipe-branching\rvest>git grep 'No links matched that expression'
fatal: ambiguous argument 'links': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
try with double quotes? error looks like that git thinks “links” is a file.
R/session.R: stop("No links matched that expression", call. = FALSE)
git bisect
, what should we do if at a given commit we don’t know if it is good or bad? Is there a way to tell git “I don’t know, give me the next/previous commit” ?
git bisect skip
that version.test.py
and after defining the search endpoints, I ran: git bisect run python test.py
and it located the bad commit. I suggest we look at it together via screenshare?Please give us feedback for today: one thing that you enjoyed, one thing we should change/improve:
Good:
To improve:
ensure some time to discuss the interesting discussion questions on the webpage of the course programme :+1:. I’m wondering about many of them. e.g. “Discuss how Git handles conflicts compared to the Google Drive”
git push
everything is only your local computer.:::info Always ask questions at the very bottom of this document, right above this. Switch to view mode if you are only watching.
We are monitoring this hackMD, but we will reply every now and then so that you can focus on the speaker. :::