Eclipse > git - what is Assume Valid? - eclipse

Looking through Eclipse's Label Decorations for Git, I see one with a tick that says assume-valid.txt.
What is Assume Valid?

assume-valid - The resource has the "assume unchanged" flag. This means that Git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when you change the working tree file. This setting can be switched on with the menu action Team->Assume unchanged (or on the command line with git update-index --assume-unchanged).
Check out more at https://wiki.eclipse.org/EGit/User_Guide/State

Related

Recover from Git reset --hard in Eclipse

I accidentally did something to my git repo and I don't know if I can save my project at this point...
I had a bunch of changes that I made. Then I wanted to delete my last commit so that I could make this new commit instead. I forgot to do git stash. So when I ran git reset --hard [second-to-last commit] it erased everything I had done. It was stupid, but is there anything I can do to rescue my recent work?
I'm using Eclipse IDE.
Short answer for git, NO.
It is impossible to recover file that you did not add or stash
In general the best way to handle these kind of problem is to rely on the IDE instead.
In Eclipse, you could look under this path
.metadata/.plugins/org.eclipse.core.resources/.history/
So, you could use those commands to find the most recent changes,
cd .metadata/.plugins/org.eclipse.core.resources/.history/
ls -al * | grep "<today's date>" | grep "r\-\-" | sort -k 6
Note that you will have to replace "<today's date>" with "Jul 27" for example.
Then you could use
find . -name <filename>
Note that you will have to replace "<filename>" with something like "7098a672a2bc00111703c0e5cbee369d" found with the previous command.
For more info look at this.
Unfortunately, git has no way of knowing about the file contents that you didn't commit or stash. This means you cannot restore your changes with git. Other tools might be able to help. For example, IntelliJ has a "Local History" feature that tracks all saved changes. Perhaps your editor has something similar?
You mentioned in your comments that you were using Eclipse - normally eclipse keeps a local history of changes that you were and have been making. The following steps may help in that regard:
Restoring deleted resources from local history
To restore a deleted Workbench resource with a state from the local history:
In one of the navigation views, select the folder or project into which you want to restore a local history state.
From the resource's pop-up menu, select Restore from Local History.... The Restore From Local History dialog opens showing all files that were previously contained in the selected folder or project and all of their sub-folders.
Check the files that you want to restore
If you don't want to restore just the last state of a file you can select any other state of the file from the Local History list on the right hand side of the dialog. The bottom pane of the dialog shows the contents of the state.
If you are done with all files click Restore.
Tip: You can configure your Workbench preferences to specify how many days to keep files, or how many entries per file you want to keep, or the maximum file size for files to be kept with the command link General > Workspace > Local History preference page.
this can also be found at this link: https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Ftasks%2Ftasks-87b.htm

Github version of Perforce's explicit check-out feature

I've recently moved to Github (VS2017's built-in support) from Perforce for some individual projects. There is a feature in Perforce called "make writable" that allowed you to write to a file locally and then only submit it to the server by explicitly checking it out then submitting it.
This was used extensively for any binary files (.exe, etc) that only needed to be pushed very rarely but still needed to be written to.
Unfortunately from my limited experience with Github, it seems that all files are set to writable and are always marked as "changed", even exes. Is there a setting I can make or setup that allows Github to only mark a file as changed explicitly so I can't accidentally push an incomplete, broken, or debug .exe?
Updated answer: So, I forgot, if the file's tracked by Git at any point, then it gets a bit ugly. There are ways around this, but it isn't a single command to do this.
IF you want to do the .gitignore route, you can. But there's an added step (see below for first step). You have to, after each commit you do of the .exe file, run git rm --cached <filename>. This will remove the metadata around the file telling Git to track it. Once you do that, it won't show up anymore in the Changes list in the Visual Studio plugin (if you're on commandline it won't show up in git status). Then to add a file, you do what I mentioned below, which is to do the git add -f <filename>.
If instead, another way to do this, would be to run git update-index --assume-unchanged <filename>. This tells Git to ignore changes to the file. When you want to commit it, first run git update-index --no-assume-unchange <filename> and do your normal git add git commit workflow, then once you've committed it, run again the git update-index --assume-unchanged <filename> bit. It's messy, and honestly, I'd write a custom tool in VS to do this rather than relying on the built-in SCM tool in Visual Studio.
Original answer: Best way to do this (IMO, others will have their own opinion) is to add the files to your .gitignore. Then if/when you really want to commit them, do a git add -f <file> and then commit as normal.
Edit: Note that this is something everyone will have to do to avoid accidentally committing. A way around that is to commit your .gitignore as well so everyone has the same behavior.

how to hide yellow cylinder decorations on the right bottom corner of icons in project explore view?

i created a C++ project called us_txn_svc in eclipse kepler.
The workspace location is in /data/work/usfsi/, the project location in /data/work/usfsi/fsi_svc_us/us_txn_svc.
In project explore view, the proejct us_txn_svc is shown with a "remote" decoration on the icon and a suffix like " [fsi_svc_us echo]", echo is my user name on this computer. all files under this project are also shown with a "remote" decoration.
how to configurate my workspace to hide these useless infomation?
a snapshot:
The icon overlay decoration tells you the file is under version control, the information in [] gives you more version control information such as the repository.
You can usually turn all the decorations off by going to Preferences > General > Appearance > Label Decorations and unselecting your version control system (Git, SVN, CVS etc.)
You can fine tune the information shown for by version control in "Preferences > Team" ("Preferences > Version Control (Team)" in newer versions of Eclipse), select your version control system and look for Label Decorations.
Hey this should give you a good idea of this and more Eclipse Egit icons:
dirty (folder) - At least one file below the folder is dirty; that
means that it has changes in the working tree that are neither in the
index nor in the repository. tracked - The resource is known to the
Git repository. untracked - The resource is not known to the Git
repository.
ignored - The resource is ignored by the Git team
provider. Here only the preference settings under Team -> Ignored
Resources and the "derived" flag are relevant. The .gitignore file is
not taken into account.
dirty - The resource has changes in the
working tree that are neither in the index nor in the repository.
staged - The resource has changes which are added to the index. Not
that adding to the index is possible at the moment only on the commit
dialog on the context menu of a resource.
partially-staged - The resource has changes which are added to the index and additionally
changes in the working tree that are neither in the index nor in the
repository.
added - The resource is not yet tracked by but added to
the Git repository.
removed - The resource is staged for removal from
the Git repository.
conflict - A merge conflict exists for the file.
assume-valid - The resource has the "assume unchanged" flag. This
means that Git stops checking the working tree files for possible
modifications, so you need to manually unset the bit to tell Git when
you change the working tree file. This setting can be switched on
with the menu action Team->Assume unchanged (or on the command line
with git update-index--assume-unchanged).

Is it possible to ignore file recreation in git?

Some files in my project are deleted and recreated often enough. Git treats them like a completly new files and commits them as new even if the contents of the files isn't changed. Is it possible to ignore file recreation and handle them as a usual, not recreated files?
I've set core.trustctime to false, but nothing is changed.
PS: I'm using Github for Windows.
This is a bug in Eclipse that won't be fixed, unfortunately (it's from 2002).
What happens is this: Eclipse has an object to track files in the workspace. They have defined the usual operations like create and delete. So what happens is that you build your project.
This triggers the EMFText builder. It will delete the files which will trigger a "git rm" since Eclipse can't tell the difference between "code generator deletes files to create them again" and "user deleted a file for good."
Then the file is created again. Eclipse has no good way to fell whether you want to have this delete in your commit history or whether this was unintentional. So the file stays in the deleted state.
MercurialEclipse and all other version control plugins on Eclipse are affected as well.
Workarounds:
Create a script which simply adds all files that exist but are in state "delete".
Configure your code generator not to delete files during "Clean". Xtext can do this.
You could try and apply a git update-index assume-unchanged directive on all the files regenerated by EMFText.
See "git update-index --assume-unchanged on directory":
cd /path/to/EMFText/generated/files
git update-index --assume-unchanged $(git ls-files | tr '\n' ' ')

Git shows files changed, but EGit does not

Git noob here. Having a hard time figuring out why git shows some files changed, while Eclipse EGit does not.
When I use EGit within Eclipse and view a project, it shows no files changed. There is no little caret next to each file. When I use Git for Windows, or go to the command line and type "git status", it shows that all the files have been modified. When I type "git diff" it shows two different versions of a file, first red, then green, and there appears to be some whitespace differences, but I can't be sure, and I can't figure out how the whitespace changed in every file in the project. (Something here doesn't add up.) "git diff -w" returns nothing. "git config --global apply.whitespace nowarn" does nothing.
I might be having a basic conceptual problem with git.
In any case, why do EGit and the git command line show different results?
EGit understands the notion of Derived resources (e.g. used for generated .class files in JDT). In other words, files in derived resources are not added to version control by default in EGit. However, the command line git client does not know these markers, but relies on .gitignore files to avoid checking in generated files.
To check whether your problematic files are derived, open the file properties dialog (right click on the file in the explorer, and select Properties...), and on the Resources page check for the Derived checkbox (it should be around the middle of the dialog).
It turns out that git is playing games with newlines. It's inexplicable. Bottom line: EGit and the git command line cannot both be used on a Windows box. To get consistency, you have to use one or the other.