Lecturer: Michael Lydeamore
Department of Econometrics and Business Statistics
Aim
With this you have learned the basics to create reproducible and collaborative reports.
“Stashing takes the”dirty” state of your working directory - that is, your modified tracked files and staged changes - and saves it on a stack of unfinished changes that you can reapply at any time (even on a different branch).” Source
git stash
comes in handy for staged files or `git stash -u for unstaged files.
git stash
allow us to keep changes in our local repository and to commit then later on.
git stash save "Message"
allow us to add a message to the stash
git stash
Creating a stash allows you to revert but save changes that you might have done in the repository, without losing them.
Then, when you are ready to include those changes and to commit them into the remote repo we can use:
git stash apply
makes your changes in the stash on the branch but keeps them in the stash.git stash pop
makes your changes in the stash on the branch and removes them from the stash.Generally, pop
is preferred unless you have to apply your changes more than once.
git stash
in practice$ git status
On branch master
Changes to be committed:
new file: style.css
Changes not staged for commit:
modified: index.html
$ git stash
Saved working directory and index state WIP on master:
5002d47 our new homepage
HEAD is now at 5002d47 our new homepage
$ git status
On branch master
nothing to commit, working tree clean
Important
stash
es are not transferred to the server when you push.
You can create more than one stash: be careful with this.
git apply
and git pop
: stage changesThe git stash
command takes your uncommitted changes but staged and saves them away for later use, or git stash -u
if we have not staged the changes, and then reverts them from your working copy. git stash
save “Message to remember what you did”
To bring stash in from the repo:
git stash apply
git stash pop
git stash apply
git stash apply
will take the changes saved in your stash and apply them into the working directory of your current branch. In addition, the changes are kept in the stash. This might be useful when you want to apply the same changes into different branches.
git stash pop
git stash pop
will do the same as apply but will delete the stash after applying the changes.
Important
The stash is not a replacement for a commit. You can think of stashing as ‘keeping for later’, while a commit is for saving and keeping record.
git stash pop
in practice$ git status
On branch master
nothing to commit, working tree clean
$ git stash pop
On branch master
Changes to be committed:
new file: style.css
Changes not staged for commit:
modified: index.html
Dropped refs/stash@{0} (32b3aa1d185dfe6d57b3c3cc3)
git stash apply
in practicegit stash apply
On branch master
Changes to be committed:
new file: style.css
Changes not staged for commit:
modified: index.html
Do you see the difference between pop
and apply
?
git stash list
will list all of your stashes
$ git stash list
stash@{0}: WIP on dev: 1f6f8bb Commit message A
stash@{1}: WIP on master: 50cf63b Commit message B
git stash show stash@{1}
will show you the files changed in stash@{1}
git stash apply/pop
twicegit stash apply stash@{0}
git stash pop stash@{1}
git stash drop stash@{0}
will delete stash@{0}
git stash clear
will remove all the stashes in the stash area.Important
Because stashes aren’t synchronised, once they’re gone they’re gone. So, clear with caution.
If you stash some work, leave it there for a while, and continue on the branch from which you stashed the work, you may have a problem reapplying the work. If the apply tries to modify a file that you’ve since modified, you’ll get a merge conflict and will have to try to resolve it.
If you want an easier way to test the stashed changes again, you can run git stash branch branchname
, which creates a new branch for you with your selected branch name, checks out the commit you were on when you stashed your work, reapplies your work there, and then drops the stash if it applies successfully.
Git sees every file in your working copy as one of three things:
Typically in a project there might be files that we decided to not track and ignore.
Examples include files that are built artifacts and machine generated files that can be derived from your repository source or should otherwise not be committed.
Ignored files are tracked in a special file named .gitignore
that is checked in at the root of your repository.
git ignore
command: instead Git uses a .gitignore
file which must be edited and committed by hand when you have new files that you wish to ignore..gitignore
files contain special patterns which are comapred against filenames to determine whether or not they should be ignored.gitignore
patterns.gitignore
file# ignore all logs
*.log
# History files
.Rhistory
.Rapp.history
# Session Data files
.RData
# User-specific files
.Ruserdata
# Example code in package build process
*-Ex.R
From the command line you can create a .gitignore
file for your repository.
touch .gitignore
You can edit the file using Rstudio or VSCode.
You can also create a .gitignore
file from GitHub.
You can edit it later using RStudio or VSCode.
.gitignore
fileIf you want to ignore a file that is already checked in, you have to untrack it before you add it to the .gitignore
.
Do to this, from your terminal/Git Bash Shell:
$ git rm --cached FILENAME
The gitignore
file specifies intentionally untracked files to ignore.
Each line in a gitignore file specifies a pattern.
gitignore
fileTip
git add
and git commit
are local operations.
git push
, git pull
, and git fetch
are operations that interact with a remote repository.
A fork is a copy of a repository.
Search/navigate repo from within our Github account.
To do this, the other person can make a pull request. This makes a request to the repositories owner to pull or merge these changes into the original repository.
Please make sure you have R and Rstudio locally installed
Please make sure that your GitHub is connected to VSCode and VSCode is installed.
We are now set to start using this tools and create collaborative and reproducible reports! From now on we will learn more on creating beautiful and reproducible reports!
Next week we will discuss the importance of reproducible reporting and the usage of version control systems. We will do few hands on exercises so please make sure you bring your computer to the lecture.
Recap
ETC5513 Week 5